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.  [ 7 posts ] 
Author Message
 Post subject: Problem Hibernate Tool with ANT
PostPosted: Fri Jul 25, 2008 5:31 am 
Newbie

Joined: Fri Jul 25, 2008 4:03 am
Posts: 7
Hi,

I'm trying to create java files from an existing database schema.
But hibernate tool does not generate code ... but it also does not generate an error.
I think the problem is that sessionfactory is null, but I don't know why.
When I use the hibernate.cfg.xml in my application I'm getting a connection

hibernate.cfg.xml

Code:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>
      <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
       <property name="connection.url">jdbc:mysql://localhost:3306/schufa</property>
       <property name="connection.username">root</property>
        <property name="hibernate.hbm2ddl.auto">validate</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>


        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
       
    </session-factory>

</hibernate-configuration>


Ant Task:

Code:
<project basedir="." default="hibernate">
<!--    <property name="jdbc.driver.jar" value="C:/Program Files/Oracle/ora91/jdbc/lib/ojdbc14.jar" /> -->

   <property name="jdbc.driver.jar" value="../../IWAModCore/lib/mysql-connector-java-5.1.6-bin.jar" />

   <path id="toolslib">
      <path location="../../IWAModCore/lib/hibernate-tools.jar" />
      <path location="../../IWAWeb/WebContent/WEB-INF/lib/hibernate3.jar" />
      <path location="../../IWAWeb/WebContent/WEB-INF/lib/freemarker-2.3.8.jar" />
      <path location="../../IWAWeb/WebContent/WEB-INF/lib/commons-logging-1.1.1.jar" />
      <path location="../../IWAWeb/WebContent/WEB-INF/lib/dom4j-1.6.1.jar" />
      <path location="${jdbc.driver.jar}" />
   </path>
      
   <taskdef name="hibernatetool"
            classname="org.hibernate.tool.ant.HibernateToolTask"
            classpathref="toolslib" />
   
   <property name="gen.dir" location="${basedir}/hibernate/gen"/>
   

   <target name="hibernate">
      <mkdir dir="${gen.dir}"/>
      <hibernatetool destdir="${gen.dir}">
         <configuration configurationfile="../src/hibernate.cfg.schufa.xml"/>      
         <hbm2java ejb3="true" jdk5="true" />
      </hibernatetool>
   </target>

</project>


Output:

Code:
parsing buildfile C:\Workspaces\workspace_iwa\IWAModSchufa\hibernate\build.xml with URI = file:///C:/Workspaces/workspace_iwa/IWAModSchufa/hibernate/build.xml
Project base dir set to: C:\Workspaces\workspace_iwa\IWAModSchufa\hibernate
Build sequence for target(s) `hibernate' is [hibernate]
Complete build sequence is [hibernate, ]
hibernate:
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: hbm2java (Generates a set of .java files)
[hibernatetool] 24.07.2008 16:19:16 org.hibernate.cfg.Environment <clinit>
[hibernatetool] INFO: Hibernate 3.2.6
[hibernatetool] 24.07.2008 16:19:16 org.hibernate.cfg.Environment <clinit>
[hibernatetool] INFO: hibernate.properties not found
[hibernatetool] 24.07.2008 16:19:16 org.hibernate.cfg.Environment buildBytecodeProvider
[hibernatetool] INFO: Bytecode provider name : cglib
[hibernatetool] 24.07.2008 16:19:16 org.hibernate.cfg.Environment <clinit>
[hibernatetool] INFO: using JDK 1.4 java.sql.Timestamp handling
[hibernatetool] 24.07.2008 16:19:17 org.hibernate.cfg.Configuration configure
[hibernatetool] INFO: configuring from file: hibernate.cfg.schufa.xml
[hibernatetool] 24.07.2008 16:19:17 org.hibernate.cfg.Configuration doConfigure
[hibernatetool] INFO: Configured SessionFactory: null
[hibernatetool] 24.07.2008 16:19:17 org.hibernate.tool.Version <clinit>
[hibernatetool] INFO: Hibernate Tools 3.2.1.GA
BUILD SUCCESSFUL
Total time: 907 milliseconds


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 29, 2008 7:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you have no entities listed in your cfg.xml ...so no generation is expected.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 29, 2008 11:11 am 
Newbie

Joined: Fri Jul 25, 2008 4:03 am
Posts: 7
max wrote:
you have no entities listed in your cfg.xml ...so no generation is expected.


Yes, but I want to generate the entities from my database model, so there are no java files or hbm.xml yet.

How do I do that?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 9:56 am 
Regular
Regular

Joined: Tue Jul 29, 2008 4:15 pm
Posts: 62
Location: Dallas, TX US
Hi,

If you have an existing database you should be able to reverse engineer it via the reverse engineering from JDBC Connection option. But first you have to set up the Hibernate Configuration and Hibernate console. This process is straight forward. I didn't have to muck with the ant script to do this. See Hibernate Tools viewlets to instructions. http://www.hibernate.org/Modules/HibernateToolsViewlets


I don't think the Hibernate Tools plugin for Eclipse supports hbm2java as I have try to generate my POJOs from only my hbm files. Or at least I have not figured out how to do this, yet with the Hibernate Tools plugin with Eclipse. See my earlier post for details: http://forum.hibernate.org/viewtopic.php?t=989183

So I am going to try to just run the hbm2java through ant via eclipse.

Hope this helps!

Thanks!

_________________
pouncilt


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 10:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
in eclipse hbm2java option is available under Exporters.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 11:34 am 
Regular
Regular

Joined: Tue Jul 29, 2008 4:15 pm
Posts: 62
Location: Dallas, TX US
Max,

First of all let me take the time to thank you for replying to my post. Thanks a Million!

Now to business... Can you be a little clearer in describing this option and how you actually invoke it?

My understanding of the hbm2java tool is to generate Java object from the hbm.xml configuration files. Is that correct?

My understanding of the exporters is to generate the below artifacts when you check them. So if I check the Hibernate XML Mapping checkbox, the exporter would generate the hbm.xml configuration files for me. Is this correct?

So if my understanding is correct, then you can see how these exporters do not help me; because I already have created my hbm.xml configuration files. I don't want to tool to generate it again for me. I want to tool to use my already existing hbm.xml file to generate my domain code via the Domain Code checkbox in the exporter section of the HTools.

In the HTools Code Generation console, I see the exporter tab. When I click on the exporter tab I see the following:
Checkbox for Using Java 5 syntax
Checkbox for Generating EJB3 annotations.
Checkbox for Domain code.
Checkbox for Hibernate XML Mappings.
Checkbox for DAO code.
Checkbox for Generic Exporter.
Checkbox for Hibernate XML Configuration.
Checkbox for Schema Documentation.
Checkbox for Schema Export.

There is a property/value section where you can add properties and values. I am guess these properties/values can be used inside the different configuration files defined in the exporters above. Is that right?

So which on of the checkboxes above will do what I am looking for; which is to generate my Java domain objects based off of my existing hbm.xml files?

Thanks Again!

_________________
pouncilt


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 2:10 pm 
Regular
Regular

Joined: Tue Jul 29, 2008 4:15 pm
Posts: 62
Location: Dallas, TX US
I found my mistake. In my cfg.xml file it was referencing the pojo classes instead of the hbm.xml files. I am now able to generate my pojos based on my hbm.xml files.

Thanks!

_________________
pouncilt


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.