Discussion:
[Middlegen-user] Reverse from an existing database
Ray Tayek
2004-03-05 01:13:01 UTC
Permalink
Hi, newbie to hibernate (and db's in general) here. we have this existing
mysql database and I am trying to use hibernate to provide a more rational
persistance layer. Towards that end, I would like to reverse the existing
database tables directly into java objects if possible. According to the
diagram at: http://hibernate.org/102.html, middlegen will do this. I
downloaded the sample, but it seems to be going the other way. Is there any
doc around on how to do this?

Any pointers will be appreciated.

Thanks
Eivind Waaler
2004-03-05 06:36:02 UTC
Permalink
Hi, middlegen will generate the hibernate xml mapping files from your
database. Then you can use hibernates hbm2java tool to generate the java
files.

Just set up middlegen to run against your database. The sample build.xml
script includes a target to run hbm2java, which depends on the middlegen
target.

So set up your database, package names etc. then simply run 'ant hbm2java'
to generate the xml mappings with java files.

.eivind
Post by Ray Tayek
Hi, newbie to hibernate (and db's in general) here. we have this existing
mysql database and I am trying to use hibernate to provide a more rational
persistance layer. Towards that end, I would like to reverse the existing
database tables directly into java objects if possible. According to the
diagram at: http://hibernate.org/102.html, middlegen will do this. I
downloaded the sample, but it seems to be going the other way. Is there any
doc around on how to do this?
Any pointers will be appreciated.
Thanks
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
Russell Simpkins
2004-03-05 10:58:01 UTC
Permalink
Middlegen works really well. For you to use Middlegen out of the box,
you need to change the mess with build.properties and/or build.xml file
so that it points to your database. In build.xml you should see this
<!ENTITY database SYSTEM "file:./config/database/hsqldb.xml">
(http://boss.bekk.no/boss/middlegen/getstarted/index.html). Change that
to point to mysql.xml then go and either adjust mysql.xml or your
build.properties file to set server/db/user/password. Also, change the
project name in the build.xml file. FYI, the middlegen plugin only
creates the hibernate config files. If you want java files, you either
have to create your own velocity template or better yet, use Hibernates
sql2java routine. I created my own velocity template that uses the
middlegen Java plugin
http://boss.bekk.no/boss/middlegen/plugins/java.html to create java with
xdoclet tags.

Hope that helps.


-----Original Message-----
From: middlegen-user-***@lists.sourceforge.net
[mailto:middlegen-user-***@lists.sourceforge.net] On Behalf Of Ray
Tayek
Sent: Thursday, March 04, 2004 10:04 PM
To: middlegen-***@lists.sourceforge.net
Subject: [Middlegen-user] Reverse from an existing database

Hi, newbie to hibernate (and db's in general) here. we have this
existing
mysql database and I am trying to use hibernate to provide a more
rational
persistance layer. Towards that end, I would like to reverse the
existing
database tables directly into java objects if possible. According to the
diagram at: http://hibernate.org/102.html, middlegen will do this. I
downloaded the sample, but it seems to be going the other way. Is there
any
doc around on how to do this?

Any pointers will be appreciated.

Thanks



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
Ray Tayek
2004-03-05 16:50:02 UTC
Permalink
Post by Russell Simpkins
-----Original Message-----
Of Eivind Waaler
Sent: Friday, March 05, 2004 12:21 AM
Subject: Re: [Middlegen-user] Reverse from an existing database
Just set up middlegen to run against your database.
Done
Post by Russell Simpkins
sample build.xml script includes a target to run hbm2java,
which depends on the middlegen target.
So set up your database, package names etc. then simply run
'ant hbm2java' to generate the xml mappings with java files.
I am getting a ant not task found for the middlegen task. Is it in one of
the jars? (doesn't seem to be in hib2.jar or hib tools jar. Maybe this is an
optional ant task I need to get from ant? Does it need to go into the ant
lib (like junit)?

Will it somehow export the database schema? (or do I not care)?

thanks
Post by Russell Simpkins
... existing mysql database ...
reverse the existing database tables directly into java objects if
http://hibernate.org/102.html, ...
Ray Tayek
2004-03-05 16:57:01 UTC
Permalink
Post by Russell Simpkins
-----Original Message-----
Of Russell Simpkins
Sent: Friday, March 05, 2004 4:43 AM
Subject: RE: [Middlegen-user] Reverse from an existing database
... you need to change the mess with build.properties
mysql.xml or your build.properties file to set
server/db/user/password. Also, change the project name in the
build.xml file.
Will do.
Post by Russell Simpkins
... If you want java files, you either
have to create your own velocity template or better yet, use
Hibernates sql2java routine.
I will check this out.
Post by Russell Simpkins
I created my own velocity
template that uses the middlegen Java plugin
http://boss.bekk.no/boss/middlegen/plugins/java.html to
create java with xdoclet tags.
Looks interesting.

Thanks
Post by Russell Simpkins
-----Original Message-----
Of Ray Tayek
Sent: Thursday, March 04, 2004 10:04 PM
Subject: [Middlegen-user] Reverse from an existing database
... existing mysql database and I am trying to use hibernate
... I would like to reverse the existing database tables
directly into java objects if possible. ...
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
Ray Tayek
2004-03-05 18:32:07 UTC
Permalink
Post by Russell Simpkins
-----Original Message-----
Of Eivind Waaler
Sent: Friday, March 05, 2004 12:21 AM
Subject: Re: [Middlegen-user] Reverse from an existing database
Hi, middlegen will generate the hibernate xml mapping files
from your database. Then you can use hibernates hbm2java tool
to generate the java files.
Just set up middlegen to run against your database. The
sample build.xml script includes a target to run hbm2java,
which depends on the middlegen target.
Done
Post by Russell Simpkins
So set up your database, package names etc. then simply run
'ant hbm2java' to generate the xml mappings with java files.
I get a can't find the middlegenTask fron ant. Where does it live? And does
it have to be also place in ant/lib (like junit.jar)? (it does not seem to
be in the hib or hib tools jar).\

Sorry abou the possible duplicate post. I thought I posted a reply from home
using pcanywhere and it shows sent in outlooj, but has not shown up yet on
the list.

thanks
Post by Russell Simpkins
Post by Ray Tayek
Hi, newbie to hibernate (and db's in general) here. we have this
existing mysql database and I am trying to use hibernate to
provide a
Post by Ray Tayek
more rational persistance layer. Towards that end, I would like to
reverse the existing database tables directly into java objects if
http://hibernate.org/102.html,
Post by Ray Tayek
middlegen will do this. I
downloaded the sample, but it seems to be
Post by Ray Tayek
going the other way. Is there any doc around on how to do this?
...
Ray Tayek
2004-03-05 20:10:35 UTC
Permalink
Post by Russell Simpkins
-----Original Message-----
Of Ray Tayek
Sent: Friday, March 05, 2004 12:22 PM
Subject: RE: [Middlegen-user] Reverse from an existing database
Post by Russell Simpkins
-----Original Message-----
Of Eivind Waaler
Sent: Friday, March 05, 2004 12:21 AM
Subject: Re: [Middlegen-user] Reverse from an existing database
Hi, middlegen will generate the hibernate xml mapping files
from your database. Then you can use hibernates hbm2java tool
to generate the java files....
I get a can't find the middlegenTask fron ant. Where does it
live?...
Found it in the obvious place :(
Middlegen is making mapping files and hbm2java is making source code.
This is a really great tool - a thousand thaky you's to tge dev team.
(clearly saving me hundreds of hours of work :)

Now trying to throw away all the stuff in the build file that has nothing to
do with reverse.

thanks

Loading...