-->
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: problem with hbm2java and joined-subclass
PostPosted: Wed Apr 06, 2005 5:54 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
I am fairly new to Hibernate. I'm trying to use hbm2java to generate code, and am having a problem using a 'joined-subclass'. I am using Hibernate 2.1.3. Here are my hbm files:

User.hbm.xml:

<hibernate-mapping>
<class
name="com.nathan.hibernatetest.User"
table="user"
>
<id
name="user_id"
type="integer"
column="user_id"
>
<generator class="native" />
</id>

<property
name="username"
type="java.lang.String"
column="username"
not-null="true"
length="32"
/>
</class>
</hibernate-mapping>

and Teacher.hbm.xml:

<hibernate-mapping>
<joined-subclass
name="com.nathan.hibernatetest.Teacher"
table="teacher"
extends="com.nathan.hibernatetest.User"
>

<key column="user_id"/>

<property
name="lastlogin"
type="java.sql.Timestamp"
column="lastlogin"
not-null="true"
length="8"
/>

</joined-subclass>
</hibernate-mapping>


When I run hbm2java, I get the following stack trace:

Buildfile: C:\dev\test\hibernatetest\build.xml
genwfpojos:
[hbm2java] Processing 2 files.
[hbm2java] Building hibernate objects
[hbm2java] net.sf.hibernate.MappingException: Cannot extend unmapped class com.nathan.hibernatetest.User
[hbm2java] at net.sf.hibernate.tool.hbm2java.CodeGenerator.handleClass(CodeGenerator.java:137)
[hbm2java] at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:109)
[hbm2java] at net.sf.hibernate.tool.hbm2java.Hbm2JavaTask.processFile(Hbm2JavaTask.java:145)
[hbm2java] at net.sf.hibernate.tool.hbm2java.Hbm2JavaTask.execute(Hbm2JavaTask.java:95)
[hbm2java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
[hbm2java] at org.apache.tools.ant.Task.perform(Task.java:364)
[hbm2java] at org.apache.tools.ant.Target.execute(Target.java:341)
[hbm2java] at org.apache.tools.ant.Target.performTasks(Target.java:369)
[hbm2java] at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
[hbm2java] at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
[hbm2java] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:377)
[hbm2java] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:135)
BUILD SUCCESSFUL
Total time: 1 second

If I place the Teacher joined-subclass inside the User class, it works fine. THe DTD seems to imply that I can have a joined-subclass separately from its parent class, but I can't get it to work. What am I doing wrong? Thanks in advance for your help!

Nathan


Top
 Profile  
 
 Post subject: additional info
PostPosted: Thu Apr 07, 2005 4:06 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
I narrowed it down to some aspect of the ant task. I created another ant task that just ran CodeGenerator directly, and that worked fine, while the Hbm2JavaTask task still failed - everything else being identical. Here are my tasks:

<target name="generatejava" depends="init">
<taskdef
name="hbm2java"
classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
classpathref="class.path" />
<hbm2java classpathref="class.path">
<fileset dir="${basedir}">
<include name="src/com/nathan/hibernatetest/User.hbm.xml" />
<include name="src/com/nathan/hibernatetest/Teacher.hbm.xml" />
</fileset>
</hbm2java>
</target>

<target name="runhbm2java" depends="init">
<java dir="${basedir}"
classpathref="class.path"
classname="net.sf.hibernate.tool.hbm2java.CodeGenerator">
<arg value="src/com/nathan/hibernatetest/User.hbm.xml"/>
<arg value="src/com/nathan/hibernatetest/Teacher.hbm.xml"/>
</java>

</target>

generatejava task fails with the previously posted error. runhbm2java runs perfectly. Still no clue if I'm doing something wrong, or there is a bug in Hbm2JavaTask.

Anyway, I have switched to Hibernate 3.0 and the Eclipse plugin for generating java source, and that seems to be working, also. So I have a workaround in Hibernate2, and no problems with Hibernate3. The reason I didn't switch to Hibernate 3.0 in the first place is because the tools are an alpha release, but they seem to be working great. Problem solved. Thanks, Hibernate Team, for a great product.


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.