I have the following issue working just fine with Eclipselink, but it does not work with Hibernate. This is the error I receive:
Caused by: org.hibernate.MappingException: No type name
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:319)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:310)
at org.hibernate.mapping.IndexedCollection.validate(IndexedCollection.java:90)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1362)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1849)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
The error is caused when the field referenced by @MapKey also has an attribute converter through @Convert. If I remove @Convert, the error goes away. However, I really prefer to use @Convert so I can control how that field is outputted to the database.
This is how you reproduce the problem:
public class Parent {
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
@MapKey(name = "locale")
Map<Locale, Child> children;
}
public class Child {
@ManyToOne
private Parent parent;
@Convert(converter = MyLocaleConverter.class)
private Locale locale;
}
@Converter
public class MyLocaleConverter implements AttributeConverter<Locale, String> {
@Override
public String convertToDatabaseColumn(Locale attribute) {
return attribute.toLanguageTag();
}
@Override
public Locale convertToEntityAttribute(String dbData) {
return (dbData != null) ? Locale.forLanguageTag(dbData) : null;
}
}
|