-->
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.  [ 12 posts ] 
Author Message
 Post subject: How to create mapping files from existing tables?
PostPosted: Fri Mar 30, 2007 5:33 pm 
Newbie

Joined: Fri Mar 30, 2007 5:28 pm
Posts: 8
We are trying to re-engineer our platform code to use Hibernate. We already have the database with all tables. Is there a tool or way to directly generate class mapping files from the existing tables


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 31, 2007 1:55 am 
Newbie

Joined: Sat Mar 24, 2007 8:14 am
Posts: 15
if u r using eclipse then there is hibernate eclipse plugin so with the help of that u can make ur hbm file easily/automatically

and u can get it on eclipse website.


Top
 Profile  
 
 Post subject: How to create mapping files from existing tables?
PostPosted: Wed Apr 04, 2007 4:07 pm 
Newbie

Joined: Fri Mar 30, 2007 5:28 pm
Posts: 8
We are using IBM Websphere Studio Application Developer. Do you have an idea about this one


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 2:23 am 
Newbie

Joined: Sat Mar 24, 2007 8:14 am
Posts: 15
hope this link will help u out.

http://www.myeclipseide.com/ContentExpr ... id-61.html

Regards,

Dont forget to rate


Top
 Profile  
 
 Post subject: The other way which kinda works
PostPosted: Thu Apr 05, 2007 4:28 am 
Newbie

Joined: Thu Mar 15, 2007 1:22 am
Posts: 11
MIddlegen is a tool that is a bit behind, they are still using Hibernate 2.X DTD's however,
It will get you MOST of the way there, and then the learning curve will be MUCH smaller.
I'v attached the URL to middlegen. Very easy to get working complete with samples.
You really only need the middlegen binary download. It even includes a to inspect the links between your tables.

http://boss.bekk.no/boss/middlegen/

Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 5:54 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Folks, the right tool is called "Hibernate Tools", for Ant and Eclipse (so use Ant if you have some other IDE variation), and it's available if you click on "Hibernate Tools" on this website: http://www.hibernate.org/

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: Oh how the might have fallen :)
PostPosted: Thu Apr 05, 2007 3:28 pm 
Newbie

Joined: Thu Mar 15, 2007 1:22 am
Posts: 11
Christian,

Some of us are new to hibernate, and rely on examples. Since the documentation is EXTREMLEY week with examples in a NON-gui environment (granted there is the reference), it was difficult to figure out the correct ant lines for my build.xml. As a result, I ended up finding some demo's from middlegen on creating the task, using (agreed) older versions of hibernate's dtd. Most people on the forum, are well above my level with the use of hibernate and as such searching around I have not found many "ant" examples. Lots of nice IDE examples but since IDE's are of the devil ;), I prefer the old fashioned ant/vi method. If you happen to know of a good example using hibernate tools in ant to generate hbm's from an existing database please share.

Thanks

PS> It might be helpful to have your docs have to versions one without customer supplied examples and one with. Similar to postgresql.org's docs


Top
 Profile  
 
 Post subject: Oh how the might have fallen :)
PostPosted: Thu Apr 05, 2007 3:29 pm 
Newbie

Joined: Thu Mar 15, 2007 1:22 am
Posts: 11
Christian,

Some of us are new to hibernate, and rely on examples. Since the documentation is EXTREMLY weak with examples in a NON-gui environment (granted there is the reference), it was difficult to figure out the correct ant lines for my build.xml. As a result, I ended up finding some demo's from middlegen on creating the task, using (agreed) older versions of hibernate's dtd. Most people on the forum, are well above my level with the use of hibernate and as such searching around I have not found many "ant" examples. Lots of nice IDE examples but since IDE's are of the devil ;), I prefer the old fashioned ant/vi method. If you happen to know of a good example using hibernate tools in ant to generate hbm's from an existing database please share.

Thanks

PS> It might be helpful to have your docs have to versions one without customer supplied examples and one with. Similar to postgresql.org's docs


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 3:58 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
There are perfect examples for Hibernate Tools, with source code, available if you click the red "Quickstart" buttons on the www.hibernate.org homepage.

http://www.hibernate.org/152.html

You can download the PDF here: http://www.manning.com/bauer2 and the sourcecode with read-to-run Ant tasks for reverse engineering here: http://caveatemptor.hibernate.org

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: Guess, im just dumb
PostPosted: Thu Apr 05, 2007 4:28 pm 
Newbie

Joined: Thu Mar 15, 2007 1:22 am
Posts: 11
I have read the freely available stuff that you listed and haven't found what im looking for(Was up till 5am last night doing this). The book would probably have it in it and I may just go check that out. Thanks for your help

I just feel like hibernates site is as useful as HP's

-T

Just a dumb example like
[code]
<target name="middlegen"
description="Run Middlegen to describe the hbm.xml files from an existing schema">
<taskdef name="middlegen"
classname="middlegen.MiddlegenTask" classpathref="libraries" />
<middlegen appname="${name}"
prefsdir="${config}"
gui="false"
databaseurl="${database.url}"
driver="${database.driver}"
username="${database.userid}"
password="${database.password}"
schema="${database.schema}"
catalog="${database.catalog}"
includeViews="false">
<hibernate destination="${generated-hbm}"
package="${package.root}.reference"
genXDocletTags="false"
JavaTypeMapper="middlegen.plugins.hibernate.HibernateJavaTypeMapper" />
</middlegen>
</target>
[code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 06, 2007 2:25 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Middlegen is a 5 years old software that hasn't been maintained and definitely not made any progress for a few years AFAIK. The software that is described everywhere with plenty of examples is "Hibernate Tools".

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: Back to the topic at hand.
PostPosted: Sun Apr 08, 2007 6:50 pm 
Newbie

Joined: Thu Mar 15, 2007 1:22 am
Posts: 11
So, back to the originial question. I got it working with Hibernate Tools This is what I was using to make it work. Please anyone feel free to comment on this config.

In ant I have the following:

Code:
        <!-- HIBERNATE REQUIRED -->
        <property name="hibernate.connection.username" value="${database.userid}" />
        <property name="hibernate.connection.url" value="${database.url}" />
        <property name="hibernate.dialect" value="${database.dialect}" />
        <property name="connection.password" value="${database.password}" />
        <property name="hibernate.connection.driver_class" value="${database.driver}" />

        <taskdef name="htools" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="libraries"/>

        <target name="hbm2java" description="Generate .java from .hbm.xml files." depends="copy-resources">
                <htools destdir="${generated-java}">
                        <configuration configurationfile="${webinf}/classes/hibernate.cfg.xml"/>
                        <hbm2java jdk5="true"/>
                        <hbm2dao destdir="${generated-java}"/>
                </htools>
        </target>

        <target name="hbm2ddl" depends="copy-resources">
                <htools destdir="${generated-schema}">
                        <configuration configurationfile="${webinf}/classes/hibernate.cfg.xml"/>
                        <hbm2ddl create="true" console="true" export="false" drop="true" outputfilename="characterForge.sql"/>
                </htools>
        </target>

        <target name="ddl2hbm" depends="copy-resources">
                <htools destdir="${generated-hbm}">
                        <jdbcconfiguration
                                           configurationfile="${webinf}/classes/hibernate.cfg.xml"
                                           packagename="net.digitalassembly.characterforge.reference"/>
                        <hbm2hbmxml/>
                </htools>
        </target>


Hope this helps with the originial question

Thomas


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