-->
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.  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Modular Mapping Files
PostPosted: Thu Sep 30, 2004 10:15 am 
Newbie

Joined: Mon Sep 27, 2004 3:38 pm
Posts: 18
Location: Angleton, TX
Hibernate version: 2.1

Mapping documents:
Base.hbm.xml
Code:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
   
   <class name="eg.Base" table="BASE">
      
      <id name="id" type="java.lang.Integer" unsaved-value="null">
         <meta attribute="scope-set">protected</meta>
         <column name="UID" not-null="true"/>
         <generator class="native"/>
      </id>
      
   </class>
   
</hibernate-mapping>



SubclassOne.hbm.xml
Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
   
   <joined-subclass name="eg.SubclassOne" table="SUB_ONE" extends="eg.Base">
      
      <key column="UID" />
         
   </joined-subclass>
   
</hibernate-mapping>


Ant task and target:
Code:
   <taskdef name="hbm2java" classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask" classpathref="classpath" />

   <target name="codegen">
      <hbm2java output="${src.dir}">
         <fileset dir="${src.dir}">
            <include name="**/Base.hbm.xml" />
         </fileset>
         <fileset dir="${src.dir}">
            <include name="**/SubclassOne.hbm.xml" />
            <include name="**/*.hbm.xml" />
         </fileset>
      </hbm2java>
   </target>


I know that section 5.4 of the manual says, "Use of this feature makes the ordering of the mapping documents important!" And I've also read a previous reply to the same question and have implemented the fix as specified in that messages reply, but I'm still having problems. Here is the output from my Ant task:

Code:
Buildfile: C:\eclipse3\workspace\Hibernate\build.xml
codegen:
[hbm2java] Processing 3 files.
[hbm2java] Building hibernate objects
[hbm2java] 09:03:54,340  INFO Generator:95 - Generating 1 in C:\eclipse3\workspace\Hibernate\src
[hbm2java] 09:03:54,387  INFO Generator:95 - Generating 1 in C:\eclipse3\workspace\Hibernate\src
[hbm2java] net.sf.hibernate.MappingException: Cannot extend unmapped class eg.Base
[hbm2java] at net.sf.hibernate.tool.hbm2java.CodeGenerator.handleClass(CodeGenerator.java:147)
[hbm2java] at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:118)
[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:269)
[hbm2java] at org.apache.tools.ant.Task.perform(Task.java:364)
[hbm2java] at org.apache.tools.ant.Target.execute(Target.java:301)
[hbm2java] at org.apache.tools.ant.Target.performTasks(Target.java:328)
[hbm2java] at org.apache.tools.ant.Project.executeTarget(Project.java:1215)
[hbm2java] at org.apache.tools.ant.Project.executeTargets(Project.java:1063)
[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


The Base.class file is generated without any problems, but it fails to generate the SubclassOne.class file. Any suggestions?

Thanks,

JB


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 30, 2004 11:24 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
what version of hbm2java are you using ?

it should be in the newest release and for sure in CVS.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 30, 2004 11:37 am 
Newbie

Joined: Mon Sep 27, 2004 3:38 pm
Posts: 18
Location: Angleton, TX
From the readme.txt file in my tools directory:
Hibernate Tools - Tools for Hibernate
=====================================
version 2.1.2, 25. April 2004

From the readme.txt file in my hibernate-2.1 directory:
Hibernate - Relational Persistence for Idiomatic Java
=====================================================
version 2.1.4, 02. June 2004

But just for fun, I'll go ahead and get the latest and greatest releases and give it another try.

Thanks,

JB


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 30, 2004 11:59 am 
Newbie

Joined: Mon Sep 27, 2004 3:38 pm
Posts: 18
Location: Angleton, TX
Looks like 2.1.2 is the latest version for the tools. I upgraded to 2.1.6 for Hibernate, but I'm still having the same problem.

Any other suggestions?

Thanks,

JB


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 30, 2004 12:05 pm 
Newbie

Joined: Mon Sep 27, 2004 3:38 pm
Posts: 18
Location: Angleton, TX
And just for reference, here is my classpath entry in my Ant file:

Code:
   <path id="classpath">
      <pathelement location="${src.dir}" />
      <fileset dir="${lib.dir}">
         <include name="**/*.jar" />
      </fileset>
      <fileset dir="${hsqldb.dir}/lib">
         <include name="hsqldb.jar" />
      </fileset>
      <fileset dir="${hibernate.tools.dir}">
         <include name="hibernate-tools.jar" />
      </fileset>
      <fileset dir="${hibernate.tools.dir}/lib">
         <include name="jdom.jar" />
      </fileset>
      <fileset dir="${hibernate.dir}">
         <include name="hibernate2.jar" />
      </fileset>
      <fileset dir="${hibernate.dir}/lib">
         <include name="dom4j-1.4.jar" />
         <include name="cglib-full-2.0.1.jar" />
         <include name="commons-*.jar" />
         <include name="odmg-3.0.jar" />
         <include name="ehcache-0.7.jar" />
         <include name="log4j-1.2.8.jar" />
         <include name="jta.jar" />
      </fileset>
   </path>


Top
 Profile  
 
 Post subject: !HELP - Can someone confirm if this is a bug?
PostPosted: Thu Sep 30, 2004 9:14 pm 
Newbie

Joined: Mon Sep 27, 2004 3:38 pm
Posts: 18
Location: Angleton, TX
I've done everything I can think to do and I'm still getting the same error. Here is a copy of the console with DEBUG set in log4j for all classes:

Code:
Buildfile: F:\eclipse-3.0.1\workspace\uPDM\build.xml
codegen:
[hbm2java] Processing 2 files.
[hbm2java] Building hibernate objects
[hbm2java] 20:05:57,423 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd in classpath under net/sf/hibernate/
[hbm2java] 20:05:57,474 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd in classpath
[hbm2java] 20:05:57,874 DEBUG ClassMapping:91 - Processing mapping for class: eg.Base
[hbm2java] 20:05:58,295  INFO Generator:95 - Generating 1 in F:\eclipse-3.0.1\workspace\uPDM\src
[hbm2java] 20:05:58,435 DEBUG Generator:134 - Writing F:\eclipse-3.0.1\workspace\uPDM\src\eg\Base.java
[hbm2java] 20:05:58,495 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd in classpath under net/sf/hibernate/
[hbm2java] 20:05:58,495 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd in classpath
[hbm2java] net.sf.hibernate.MappingException: Cannot extend unmapped class eg.Base
[hbm2java] at net.sf.hibernate.tool.hbm2java.CodeGenerator.handleClass(CodeGenerator.java:147)
[hbm2java] at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:118)
[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: 7 seconds


You can see from the output that the Base.hmb.xml file is definately being processed first. Can anyone tell me why I'm still getting the [hbm2java] net.sf.hibernate.MappingException: Cannot extend unmapped class eg.Base error?

Here is the entire contents of my Ant script. I've run it from both the command line (Windows XP) and inside Eclipse 3.0.1 with the same failure.

Code:
<?xml version="1.0" encoding = "UTF-8"?>

<project name="Test" default="codegen" basedir=".">

   <!-- Project directories -->
   <property name="src.dir" value="src" />

   <!-- Project libraries -->
   <property name="hibernate.dir" value="F:\hibernate\hibernate-2.1" />
   <property name="hibernate.tools.dir" value="F:\hibernate\extensions\tools" />

   <path id="classpath">
      <pathelement location="${src.dir}" />
      <fileset dir="${hibernate.dir}">
         <include name="hibernate2.jar" />
      </fileset>
      <fileset dir="${hibernate.dir}\lib">
         <include name="**\*.jar" />
      </fileset>
      <fileset dir="${hibernate.tools.dir}">
         <include name="hibernate-tools.jar" />
      </fileset>
      <fileset dir="${hibernate.tools.dir}\lib">
         <include name="**\*.jar" />
      </fileset>
   </path>

   <!-- Custom tasks -->
   <taskdef name="hbm2java" classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask" classpathref="classpath" />

   <!-- Generate the java code for all mapping files in our source tree -->
   <target name="codegen">
      <hbm2java output="${src.dir}">
         <fileset dir="${src.dir}">
            <include name="**\Base.hbm.xml" />
         </fileset>
         <fileset dir="${src.dir}">
            <include name="**\Parent.hbm.xml" />
         </fileset>
      </hbm2java>
   </target>

</project>


Thanks,

Jeff Barriault


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 30, 2004 9:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i've fixed the bug in cvs. go check it out ;)

The ant task were calling hbm2java once per file instead of just one time with all files.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 01, 2004 3:29 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2004 3:42 pm
Posts: 36
Excellent, is this available for hibernate-2 tools too? I can only find hibernate-3 tools in CVS :(


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 01, 2004 3:34 pm 
Newbie

Joined: Mon Sep 27, 2004 3:38 pm
Posts: 18
Location: Angleton, TX
Any chance you can make a jar file available somewhere? Or can I find that in CVS somewhere (I looked but couldn't find it, but then again I'm not too familiar with CVS . . . yet). I downloaded source from CVS and started running into problems with not having ANTLR, and I really don't have the time to go and fix everything so I can compile Hibernate. If not, no big deal. I'll just create one huge monolithic mapping file until the next release comes out.

Thanks,

JB


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 01, 2004 3:43 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2004 3:42 pm
Posts: 36
Think I found it:

cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/hibernate checkout -r v21branch HibernateExt

Trying it right now


Top
 Profile  
 
 Post subject: Still Doesn't Work!
PostPosted: Sun Oct 03, 2004 6:25 pm 
Newbie

Joined: Mon Sep 27, 2004 3:38 pm
Posts: 18
Location: Angleton, TX
I downloaded all the files in CVS that were under HibernateExt/tools/scr/java/org/hibernate/tool/hbm2java, compiled them, and put them in a hbm2java.jar file. I also downloaded the 3.0 alpha release of hibernate. My ant buildfile is:

Code:
<?xml version="1.0" encoding = "UTF-8"?>

<!-- uPDM (MicroPDM) - A PDM library based on the PDX standard. -->
<!-- Copyright (c) 2004 Jeff Barriault -->

<project name="uPDM" default="codegen" basedir=".">

   <!-- Project directories -->
   <property name="src.dir" value="src" />

   <!-- Project libraries -->
   <property name="hibernate.dir" value="F:\hibernate\hibernate-3.0alpha" />
   <property name="hibernate.tools.dir" value="F:\hibernate\extensions\tools" />

   <path id="classpath">
      <pathelement location="${src.dir}" />
      <fileset dir="${hibernate.dir}">
         <include name="hibernate3.jar" />
      </fileset>
      <fileset dir="${hibernate.dir}\lib">
         <include name="**\*.jar" />
      </fileset>
      <fileset dir="${hibernate.tools.dir}">
         <include name="hbm2java.jar" />
      </fileset>
      <fileset dir="${hibernate.tools.dir}\lib">
         <include name="**\*.jar" />
      </fileset>
   </path>

   <!-- Custom tasks -->
   <taskdef name="hbm2java" classname="org.hibernate.tool.hbm2java.Hbm2JavaTask" classpathref="classpath" />

   <!-- Generate the java code for all mapping files in our source tree -->
   <target name="codegen">
      <hbm2java output="${src.dir}">
         <fileset dir="${src.dir}">
            <include name="**\Base.hbm.xml" />
            <include name="**\Parent.hbm.xml" />
         </fileset>
      </hbm2java>
   </target>

</project>


I'm still getting the following errors:
Code:
Buildfile: F:\eclipse-3.0.1\workspace\uPDM\build.xml
codegen:
[hbm2java] Processing 2 files.
[hbm2java] Building hibernate objects
[hbm2java] 15:07:41,518 DEBUG DTDEntityResolver:42 - trying to locate http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd in classpath under org/hibernate/
[hbm2java] 15:07:41,588 DEBUG DTDEntityResolver:46 - http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd not found in classpath
[hbm2java] 15:07:42,439 DEBUG ClassMapping:88 - Processing mapping for class: eg.Base
[hbm2java] 15:07:42,740  INFO Generator:93 - Generating 1 in F:\eclipse-3.0.1\workspace\uPDM\src
[hbm2java] 15:07:42,900 DEBUG Generator:132 - Writing F:\eclipse-3.0.1\workspace\uPDM\src\eg\Base.java
[hbm2java] 15:07:42,970 DEBUG DTDEntityResolver:42 - trying to locate http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd in classpath under org/hibernate/
[hbm2java] 15:07:42,990 DEBUG DTDEntityResolver:46 - http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd not found in classpath
[hbm2java] org.hibernate.MappingException: Cannot extend unmapped class eg.Base
[hbm2java] at org.hibernate.tool.hbm2java.CodeGenerator.handleClass(CodeGenerator.java:147)
[hbm2java] at org.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:118)
[hbm2java] at org.hibernate.tool.hbm2java.Hbm2JavaTask.processFile(Hbm2JavaTask.java:145)
[hbm2java] at org.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: 7 seconds


Any suggestions?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 03, 2004 6:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
use the hbm2java in the branch....it's more stable.

and note that for H3 mappingfiles you should point to H3.dtd, not 2.x (huge performance diff ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 04, 2004 8:36 am 
Newbie

Joined: Mon Sep 27, 2004 3:38 pm
Posts: 18
Location: Angleton, TX
This may sound like a really dumb question. I'm using Eclipse 3.0.1, and in the CVS Perspective nothing shows up under the Branches. I'm not sure how to go about getting the hbm2java in the branch as you have suggested.

Thanks again,

JB

PS - I probably should have posted this message in the "Beginners" forum originally so I apologize in advance for asking such a simple question here.


Top
 Profile  
 
 Post subject: Not working . . . still . . .
PostPosted: Mon Oct 04, 2004 9:12 am 
Newbie

Joined: Mon Sep 27, 2004 3:38 pm
Posts: 18
Location: Angleton, TX
Since I don't know how to do it via eclipse, I went ahead and browsed the cvs repository via the website and went to the v22branch in directory /hibernate/HibernateExt/tools/src/java/net/sf/hibernate/tool/hbm2java, downloaded and compiled all the files there, and placed them into a jar. I'm still getting the same error.

Thanks,

JB


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 04, 2004 9:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
why did you not go to the v21branch as mentioned ? v22branch is dead ;)

_________________
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.  [ 20 posts ]  Go to page 1, 2  Next

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.