-->
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.  [ 6 posts ] 
Author Message
 Post subject: A little confused - basic hbm2java ANT question
PostPosted: Sat May 12, 2007 1:17 pm 
Newbie

Joined: Fri May 04, 2007 3:43 pm
Posts: 18
Why does the hbm2java task require my class files in order to generate POJO files from the mapping file? This defeats the purpose of autogenerating the .java files if I have to already have the class files! I must be doing something wrong, as this can't be the logical way of doing this...

Here's what I mean; I have the following build.xml task:

Code:
<!-- Hibernate Tools import -->
    <taskdef name="hibernatetool"
             classname="org.hibernate.tool.ant.HibernateToolTask"
             classpathref="project.classpath"/>
   
   <!-- Auto create POJOs from mapping file -->
   <target name="hibernate">
      <hibernatetool destdir="${build.dir}\gen">
         <configuration configurationfile="${src.cfg.dir}/hibernate.cfg.xml"/>
         <hbm2java jdk5="true"/>
      </hibernatetool>
   </target>
   


And when I run it I get the following error:

Code:
[hibernatetool] org.hibernate.InvalidMappingException: Could not parse mapping d
ocument from resource OracleVars.hbm.xml
[hibernatetool] org.hibernate.MappingException: class Workstations not found whi
le looking for property: Actions
[hibernatetool] java.lang.ClassNotFoundException: com.pac.server.common.oraclevars.Workstations
[hibernatetool] A class were not found in the classpath of the Ant task.
[hibernatetool] Ensure that the classpath contains the classes needed for Hibern
ate and your code are in the classpath.


My mapping file contains very basic sections, like so:
Code:
   <class name="com.pac.server.common.oraclevars.Workstations" table="WORKSTATIONS">
      <id name="id" type="int" column="ID" >
         <generator class="assigned"/>
      </id>
      <property name="Actions">
         <column name="ACTIONS"/>
      </property>
   </class>


I don't understand why hibernate-tools cares about finding my class in order to create the POJOs. Shouldn't it simply use the hbm.xml information to generate the .java files itself?


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 13, 2007 4:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
if you don't specify a type for your property hbm2java fall back to try and resolve it from the classpath.

so remember to specify the types.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 10:04 am 
Newbie

Joined: Fri May 04, 2007 3:43 pm
Posts: 18
Max,

That worked perfectly, thanks. Now I'm trying to auto-generate the mapping files, and I'm having the same problem when using hbm2hbmxml though (in that it is looking for the mapping file to already exist). So I must be missing something in my cfg.xml file as well...

Code:
<hibernate-configuration>
<session-factory>
      <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
      <property name="hibernate.connection.url">*****</property>
      <property name="hibernate.connection.username">*****</property>
      <property name="hibernate.connection.password">*****</property>
      <property name="hibernate.connection.pool_size">10</property>
      <property name="show_sql">true</property>
      <property name="dialect">org.hibernate.dialect.OracleDialect</property>
      <property name="hibernate.hbm2ddl.auto">update</property>
      <!-- Mapping files -->
     <mapping resource="OracleVars.hbm.xml"/>
</session-factory>
</hibernate-configuration>


I'm assuming there's another attribute to <mapping resouce> that I must specify, but I cannot find anything as to what it is. Any thoughts?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 10:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
eh don't list the mapping file in *.cfg.xml if it is not supposed to be there yet.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 11:17 am 
Newbie

Joined: Fri May 04, 2007 3:43 pm
Posts: 18
Hmm, ok I think I'm confusing myself then... without the reference to the map file, how does hbm2hbmxml know what tables in the database to generate map files from? When I remove my reference to the map file, it does not generate any map files.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 11:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
if you use a <jdbcconfiguration> it will go to the db and ask for all schemas.

if you specify default_schema it will only look in that

and finally you can use reveng.xml file to finecontrol what it should match.

_________________
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.  [ 6 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.