-->
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.  [ 5 posts ] 
Author Message
 Post subject: how to set up to generate hbm and POJO from db?
PostPosted: Mon Apr 03, 2006 6:49 pm 
Regular
Regular

Joined: Wed Mar 15, 2006 1:48 pm
Posts: 91
I used middelgen before and is happy with its feature for generating hbm config file and POJO classes. Now with updating to Hibernate tool, what I have done so far is set up class path in <taskdef/>, not sure what else I should do. I read some articles, it says to config <jdbcconfiguration/>. To achieve my simple tasks, what can I do in that <jdbcconfiguration/> setting? My general purpose is to provide table name through user's entry after promt, then based on this table name tools will generate hbm config file and POJO. Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 9:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Firstly the documentation is the place to start looking:
http://www.hibernate.org/hib_docs/tools/reference/en/html/

Secondly the Ant tasks are different in organisation from H2 but are much more powerful. See this basic example for just generating the POJOs from HBMs:
Code:
<target name="hbm2java" description="Generate .java from .hbm files.">
  <delete>
    <fileset dir="${hibernateDO.dir}">
      <include name="**/*.java"/>           
    </fileset>         
  </delete>
     
  <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask">
    <classpath refid="classpath.common"/>
  </taskdef>
     
  <hibernatetool destdir="${src.dir}">
    <configuration>
      <fileset dir="${src.dir}">
        <include name="**/hbm/*.hbm.xml"/>
      </fileset>
    </configuration>
    <hbm2java generics="false"/>
  </hibernatetool>

</target>


To generate the artifacts from a difference source you use a different <configuration> tags, eg <jdbcconfiguration> and then you select the output generator(s) such as <hbm2hbmxml>.

Hope this helps get you started.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 10:41 am 
Regular
Regular

Joined: Wed Mar 15, 2006 1:48 pm
Posts: 91
I did went through the doc, but failed to find explanation or sample code for generating hbm from db. Can anyone post an example for such purpose? Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 11:03 am 
Regular
Regular

Joined: Wed Mar 15, 2006 1:48 pm
Posts: 91
Also, how can I specify the table name to be reverse engineered in hibernate tool? Which ant task will handle it?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 9:29 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
One of the goals for the rewrite of the tools was to allow greater matching or sources and sinks. Meaning different inout sources and Output sinks. Inputs can be JDBC, hbm.xml, annotation classes etc See http://www.hibernate.org/hib_docs/tools/reference/en/html/ant.html#d0e710. Outputs can be POJOs, hbm.xml, DAOs, HTML, etc. See http://www.hibernate.org/hib_docs/tools/reference/en/html/ant.html#d0e796.

We do this through a standard meta data datastructure. Fortunately, hibernate has one it uses internally so we have used it for the tools (hence why it more critcal to use the correct tools built to the hibernate built but Im going off topic).

So what does this mean for you. Notice in the example I provided that you have an input stream which is a configuration. In your case you need to use the <jdbcconfiguration> since the input stream is the db meta data. Then you set the output stream. For example you use the <hbm2hbmxml> exporter to generate the hbm.xml files. You can use multiple exporters.

In the case of controlling the <jdbcconfiguration> you can set properties in the hibernate.reveng.xml file. See http://www.hibernate.org/hib_docs/tools/reference/en/html/reverseengineering.html. This allows you to control the process of tables etc to read and many other aspects. The section of the docs I have linked to will explain it all.

Hope this helps.


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