|
This issue still exists in Version 4.3.1.CR1. However, thanks Reiner, I was able to get it to work with the solution above, which should really be incorporated into the next Hibernate Tools Version.
But this fix imposed another issue. I have a UserType which is configured via a parameter like this in the class' hbm.xml-file:
<property name="status" nullable="true">
<type name="usertype.GenericEnumUserType">
<param name="enumClassName">datatypes.Status</param>
</type>
</property>
This parameter is then used to configure the return value of the usertype's returnedClass()-method. As I don't know how to read the parameter out of the Property-parameter of generateAnnTypeAnnotation() I solved it this way:
public String generateAnnTypeAnnotation(final POJOClass pojoClass, final Property property) {
final Type type = property.getType();
if (type instanceof CustomType) {
if (((CustomType) type).getUserType() instanceof GenericEnumUserType) {
String enumClassName = ((GenericEnumUserType) ((CustomType) type).getUserType()).returnedClass().getName();
return " @" + pojoClass.importType("org.hibernate.annotations.Type") + "(type=\"" + type.getName()
+ "\", parameters = { @" + pojoClass.importType("org.hibernate.annotations.Parameter")
+ "(name = \"enumClassName\", value = \"" + enumClassName + "\") })";
}
return " @" + pojoClass.importType("org.hibernate.annotations.Type") + "(type=\"" + type.getName() + "\")";
}
else {
return "";
}
}
This approach works, but I don't really like it as it's not generic. I have found out that the properties and type parameters are still stored in the POJOClass object but there seems to be signifant effort (e.g. loop through all properties, find the correct one per name) required to access these. Do you know of a more elegant way?
|