Hi,
I'm trying to use a map from a user type to a string using the following Hibernate Annotations:
Code:
@CollectionOfElements
@org.hibernate.annotations.MapKey
@Type(type="personType")
private Map<String, PersonType> types = new HashMap<String, PersonType>();
Code:
@TypeDefs({
@TypeDef(
name="personType",
typeClass=SimpleEnumUserType.class,
parameters={
@Parameter(
name=EnumUserType.CLASS_NAME,
value="package.pc.PersonType"
)
}
)
It seems that the
@Type annotation applies to
both the key and the value type, so Hibernate wants to persist the String as PersonType.
Code:
personEventDao.saveOrUpdate(personEvent);
personEvent.getTypes().put( "blabla",PersonType.MEMBER);
personEventDao.saveOrUpdate(personEvent);
The saveOrUpdate triggers a nullSafeSet in the EnumUserType for the
String (as value) which fails, since it requires a PersonType.
The user type works in several other settings.
When swapping the Map types (and changing the test), the same error happens.
Code:
@CollectionOfElements
@org.hibernate.annotations.MapKey
@Type(type="personType")
private Map<PersonType, String> types = new HashMap<PersonType, String>();
But when both
key and value are of the same type, everything works ok.
Code:
@CollectionOfElements
@org.hibernate.annotations.MapKey
@Type(type="personType")
private Map<PersonType, PersonType> types = new HashMap<PersonType, PersonType>();
I'm using Hibernate Annotations 3.3.0.ga and HSQLDB 1.8.0.7 + DBUnit 2.2 for testing.
The problem is in the context of a model driven software development (MDSD) project.
Is there a simple soultion to this problem? The knowledge of an absence of such a solution would also help me.
Thanks,
saturn