-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Can hbm2java only generate pojos that do not exist?
PostPosted: Tue May 20, 2014 8:02 pm 
Newbie

Joined: Tue May 20, 2014 7:12 pm
Posts: 1
I have defined two sets of hbm files. In my build script, I first generate pojos from one set of hbm files using hbm2java. This works perfectly. Then I try to generate pojos from the other set of hbm files. The second set of hbm files include some entities that are associated with entities defined in the first set. For example, there is many-to-one in one hbm file as the following:

<many-to-one name="department" class="Department" fetch="select" property-ref="deptId">
<column name="employeedepartment"/>
</many-to-one>

where the class "Department" refers to a pojo class generated from the first set of hbm files.

I did two experiments.

1. When I generate pojos for the second set of hbm files, I include all hbm files from the first set and put them in the source directory. This works but not what I want. The reason I do not want this is because hbm2java generates pojos for both set of hbm files.

2. Contrast to the first experiment, I do not put the first set of hbm files in the source directory. Instead, I build a jar file that contains the first set of hbm files and their corresponding pojo classes. Then I include the jar as a dependency for the maven plugin that is to generate pojos from the second set of hbm files. What I hope is that hbm2java will generate pojos for the second set of hbm files. But it does not work. When I run the build, there is NPE as the following:

Caused by: java.lang.NullPointerException
at org.hibernate.mapping.ManyToOne.createPropertyRefConstraints(ManyToOne.java:71)
at org.hibernate.cfg.HbmBinder$ManyToOneSecondPass.doSecondPass(HbmBinder.java:2837)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1716)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1423)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375)
at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:56)
at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:302)
at org.hibernate.tool.ant.HibernateToolTask.getProperties(HibernateToolTask.java:318)
at org.hibernate.tool.ant.ExporterTask.configureExporter(ExporterTask.java:94)
at org.hibernate.tool.ant.Hbm2JavaExporterTask.configureExporter(Hbm2JavaExporterTask.java:34)
at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:39)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:186)

It looks like hbm2java can not resolve the referred class in many-to-one generated from the first set of hbm files although those classes are placed in the classpath. Correct me if I am wrong.

So my question is if hbm2java supports the case in the second experiment. If yes, what is the right way?

I also include the build script here in case it helps. Note: all dependencies are omitted for saving spaces.

I appreciate your help in advance.

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>3.0</version>
<executions>
<execution>
<id>Generate hbm.cfg.xml</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<hibernatetool templatepath="${rootConfigDir}/templates">
<jdbcconfiguration propertyfile="${rootConfigDir}/hibernate.properties"
revengfile="${rootConfigDir}/hibernate.reveng.xml"
detectmanytomany="true" detectOptimisticLock="true" />
<hbm2java jdk5="true" ejb3="false"
destdir="${basedir}/target/generated-sources/src/main/java">
<configuration propertyfile="${rootConfigDir}/hibernate.properties">
<fileset dir="${basedir}/target/generated-sources/src/main/resources">
<include name="**/*.hbm.xml" />
</fileset>
</configuration>
</hbm2java>
</hibernatetool>
</configuration>
</execution>
</executions>
</plugin>


Top
 Profile  
 
 Post subject: Re: Can hbm2java only generate pojos that do not exist?
PostPosted: Tue Sep 09, 2014 7:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmm - actually not sure if this would work but in theory it should...but i dont know enough about the maven plugin to tell if it would work..also you would probably need to list the 'other set' in your cfg.xml to have hibernate know about it before referring it from somewhere else.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.