-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate ANT tool (hibernatetool) does not autodiscover
PostPosted: Wed Nov 12, 2008 11:37 am 
Newbie

Joined: Thu Aug 07, 2008 12:03 pm
Posts: 16
Hi! I'm having kind of a problem with the Hibernate tool to generate the database schema.

I would like to mention that the application itself works perfectly. But I would like to generate the database schema in a SQL file in order to give it to my DBA.

In the ant task I have eliminated all the configuration that isn't relevant for the export (like database credentials, etc). I just have the data that is -in theory- necessary to generate the export. I'm using JTA and therefore, I'll stick to <jpaconfiguration>

Here the ANT tasks:
Code:

   <target name="Generate DB Schema" depends="Compile bussiness classes that include the model">

      <!-- Hibernate tasks definition -->
      <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask">
         <classpath refid="master-classpath-with-compiled-bussiness-classes-including-the-model-with-annotated-JPA-entries"/>
           <classpath>
               <pathelement path="${resources.dir}/libs/hibernate-3.3.1/all-hibernate-jars-including-tools-and-jbosscommons"/>
           </classpath>
      </taskdef>      
      
      <!-- Lets create a temporary Hibernate configuration file to store those properties I need for the export -->
                <!-- I will need ONLY the dialect and the "autodectection" magic -->
      <propertyfile file="${dest.dir}/hibernateProperties.properties">
         <entry key="hibernate.dialect" value="mydialectwhateveritis"/>
         <entry key="hibernate.archive.autodetection" value="class,hbm"/>
      </propertyfile>
            
      <hibernatetool destdir="${dest.dir}" >
         <classpath refid="master-classpath-with-compiled-bussiness-classes-including-the-model-with-annotated-JPA-entries"/>
         
<!-- Notice that my "PU" is defined in the classpath/META-INF/persistence.xml -->
         <jpaconfigurationp ersistenceunit="PU" propertyfile="${dest.dir}/hibernateProperties.properties"/>
                  
         <hbm2ddl
            export="false"
            update="false"
            drop="true"
            create="true"
            outputfilename="exportschema.sql"
            delimiter=";"
            format="true"
            haltonerror="true"
         />
      </hibernatetool>
   </target>


Aha, easy. Now, lets see the /META-INF/persistence.xml. Just to make it work I have removed all the information that is not relevant. This is: everything (because it isn't needed by the export schema)
But I have force the exclude-unlisted-classes=false to make sure hibernate autodetects.

Code:
   <persistence-unit name="PU" transaction-type="JTA">
      <!-- Autodetect mapping classes  -->
      <exclude-unlisted-classes>false</exclude-unlisted-classes>
   </persistence-unit>


Now, it doesn't work. The task runs smothly but no class is detected so no export is done :-(

In order to test if the .hbm files are autodetected, I created a HBM file somewhere lost in the classpath like this:

Code:
    <database-object>
        <create>
           <![CDATA[
         CREATE TRIGGER hibernate_is_weird
         ]]>
        </create>
        <drop>DROP TRIGGER hibernate_is_weird</drop>
    </database-object>



I run the task and... yes, It's detected and included in the export.

Why the HBM are detected but not the annotated classes? Do I have to set anything else?

Thanks!


Hibernate tool version: latest (3.2.4.Beta1)


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

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.