[
http://opensource.atlassian.com/projects/hibernate/browse/HBX-849?page=co...
]
Reiner Saddey commented on HBX-849:
-----------------------------------
Until this issue is fixed (which in my opinion could take a considerable amount of time
due to its complex build - if it only were a Maven project), it can be worked around
yielding identical results and without any changes to released code - just by using all
the hidden marvels Hibernate Tools has to offer. Within this description, I'm assuming
that the JBoss Hibernate Eclipse plugin be used.
# Create a utility Class (e.g. Ejb3CustomTypeAnnotation) that constructs a @Type
annotation from a pojo and one of its properties.
# Within your Hibernate Code Generation Configuration, make this utility class available
by selecting the Domain code exporter and adding a property named
hibernatetool.Ejb3CustomTypeAnnotation.toolclass stating the full name of the utility
class (e.g. com.carano.fw.hibernate.util.reverse.Ejb3CustomTypeAnnotation).
# Within your Eclipse-project, create a templates/pojo directory and supply an enhanced
version of Ejb3PropertyGetAnnotation.ftl that calls Ejb3CustomTypeAnnotation.
# Within your Hibernate Code Generation Configuration, check Use custom templates und
select the templates directory (not the templates/pojo).
Et voilĂ - your POJOS will have @Type for custom types :-)
Your utility class should look similar to:
{code:java}
package com.carano.fw.hibernate.util.reverse;
import org.hibernate.mapping.Property;
import org.hibernate.tool.hbm2x.pojo.POJOClass;
import org.hibernate.type.CustomType;
import org.hibernate.type.Type;
/**
* Define Property hibernatetool.Ejb3CustomTypeAnnotation.toolclass =
* com.carano.fw.hibernate.util.reverse.Ejb3CustomTypeAnnotation
*
* Use as ${Ejb3CustomTypeAnnotation}.generateAnnTypeAnnotation(pojo,property)
* within Ejb3PropertyGetAnnotation.ftl
*/
public class Ejb3CustomTypeAnnotation {
public String generateAnnTypeAnnotation(final POJOClass pojoClass, final Property
property) {
final Type type = property.getType();
if (type instanceof CustomType) {
return " @" +
pojoClass.importType("org.hibernate.annotations.Type") +
"(type=\"" + type.getName() + "\")";
} else {
return "";
}
}
}
{code}
Your enhanced Ejb3PropertyGetAnnotation.ftl should look similar to:
{code}
<#if ejb3>
<#if pojo.hasIdentifierProperty()>
<#if property.equals(clazz.identifierProperty)>
${pojo.generateAnnIdGenerator()}
<#-- if this is the id property (getter)-->
<#-- explicitly set the column name for this property-->
</#if>
</#if>
<#if c2h.isOneToOne(property)>
${pojo.generateOneToOneAnnotation(property, cfg)}
<#elseif c2h.isManyToOne(property)>
${pojo.generateManyToOneAnnotation(property)}
<#--TODO support optional and targetEntity-->
${pojo.generateJoinColumnsAnnotation(property, cfg)}
<#elseif c2h.isCollection(property)>
${pojo.generateCollectionAnnotation(property, cfg)}
<#else>
${pojo.generateBasicAnnotation(property)}
${pojo.generateAnnColumnAnnotation(property)}
${Ejb3CustomTypeAnnotation.generateAnnTypeAnnotation(pojo,property)}
</#if>
</#if>
{code}
Tools does not insert @Type in POJOs for user types defined in
reveng.xml
-------------------------------------------------------------------------
Key: HBX-849
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HBX-849
Project: Hibernate Tools
Issue Type: Patch
Components: hbm2java, reverse-engineer
Environment: jboss-seam-1.1.0.GA, MySQL
Reporter: Zeljko Trogrlic
Assignee: Anthony Patricio
Attachments: BasicPOJOClass.java, BasicPOJOClass.java,
Ejb3PropertyGetAnnotation.ftl, HBX-849.patch, POJOClass.java
I have created reveng.xml file:
<hibernate-reverse-engineering>
<table
catalog="configuration"
name="userdb_domain_acl">
<column name="enabled"
type="com.siemens.msm.model.mapping.BooleanEnumType"
exclude="false"/>
</table>
</hibernate-reverse-engineering>
and included it in build.xml:
<jdbcconfiguration propertyfile="build.properties"
packagename="${model.package}"
revengfile="${project.home}/reveng.xml"/>
Generated POJO attribute has proper type, but user type information is missing:
@Column(name = "enabled")
@Length(max = 42)
public Boolean getEnabled() {
....
so Hibernate reports error:
3:49:31,397 INFO [TableMetadata] table found: configuration.userdb_domain_acl
13:49:31,397 INFO [TableMetadata] columns: [id, enabled, tablename, domain]
13:49:31,397 WARN [ServiceController] Problem starting service
persistence.units:ear=msmgui.ear,unitName=msmgui
javax.persistence.PersistenceException: org.hibernate.HibernateException: Wrong column
type: enabled, expected: varchar(
2)
at
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:698)
at
org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:127)
at
org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:264)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Annotations should look like this:
@Column(name = "enabled")
@Type(type="booleanEnum")
public Boolean getEnabled() {
...
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira