-->
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: Code Generation directly based on database schema?
PostPosted: Wed Nov 03, 2004 7:00 pm 
Newbie

Joined: Wed Nov 03, 2004 6:41 pm
Posts: 12
Location: Canberra/Sydney Australia
Hi,

After reading the document, I just make the comments regarding the tool set provided by hibernate:

I think the current code generation it provides is NOT a fully automated code generation -- normally, the persistence classes are derived from (driven by) the database table schema, and it would be more practical for user to generate classes directly based on current tables defined by DBA. However, it seems that the latest version of hibernate still doensn't support this and it works slightly the other way around -- it seems that it can "auto generate" the java classes but users have to first manually define the mapping file according to the database schema in order to do this, this is still the manual process as in this case we could just simply spend the same amount of time to code the persist class straight away.

Currently there are already several tools (open source like JAG or commercial) trying to do this. Since Hibernate is an industry wide well-known framework in data persistence, it seems Hibernate is left behind in this common process.

Currently there are lots of companies are using their own in-house developed tools for doing this and it is hard to find an open source tool which can achieve this in a decent and well-documented way.

It would be very nice to see Hibernate would provide a tool such that:

1. User can use it to generate Java persistence classes (with sufisticate capability in reflecting the parent-child relationship structure) directly based on the database schema and constraints, and these generated classes are to be specifically well integrated with hibernate mapping files (as the mapping files would be automatically generated from these classes).

2. These auto-generated Java persistence classes can be further modified by users and to be re-generatable later on (without removing the logics added by the users).

3. User can still have the option to use the manualy defined xml mapping files to generate Java classes, but this would be a less attractive option.

Hibernate would only become more attractive if it could cater for this feature mentioned above.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 03, 2004 7:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Currently, Middlegen is the offical schema to hbm to (using hbm2java) Java class too for the Hibernate project. It was decided some time ago that the direction the project would take is to do ORM well and we would assist other projects to build tools etc. This has worked well in many cases and not so well in others. Middlegen does a good job in this area (I am bias since I wrote the hibernate plugin) - far better than the outdated hibernate tool. To answer your questions:

1) Middlegen does this fine including the relationships generation. We use Ant tasks to chain the generation of the POJOs using Hibernate hbm2java. See the wiki for further information or the 'Hibernate in Action' Book.

2) Hbm2Java can provide this using a class hierarchy. See wiki.

3) Again, Hbm2java.

Maybe you should have a quick look at the JAOO 03 roundtrip tools demo (year old but might be helpful) to be found on the wiki.

I think this area is captured quite well. The biggest issue as that its not all integrated into a complete single IDE. Keep an eye on JBossIDE lots of things are happening its just a matter of time.


Top
 Profile  
 
 Post subject: hbm2java
PostPosted: Thu Nov 04, 2004 2:27 am 
Newbie

Joined: Wed Nov 03, 2004 6:41 pm
Posts: 12
Location: Canberra/Sydney Australia
Thanks David,

As you mentioned, we can really use the hbm2java to generate Java source based on the database schema -- that's a very good news and I will give it a try and I would compare this with another open source tool called "sql2java", which is very powerful in doing this though lack of the potential for customisation.

However, on the latest Hibernate doco (on your website), if you look at the Toolset Guide section 15.2 Code Generation, I just can't find any description regarding to how to generate java code based on the database schema, I can only see how to generate code based on the mapping files (which must be mannually created first).

So, here, does it mean the document is missing something related to the powerful feature of the hbm2java we are discussing?

If this is true, then the documentation has to be updated A.S.A.P., because it is a window to show the power of Hibernate to the world!!!


Victor


Top
 Profile  
 
 Post subject: MiddleGen
PostPosted: Thu Nov 04, 2004 8:23 pm 
Newbie

Joined: Wed Nov 03, 2004 6:41 pm
Posts: 12
Location: Canberra/Sydney Australia
Now I know that MiddleGen would priovide the Hibernate plugin in doing this.

However, it seems that it still have the problem in handling the relationship, i.e. sophisticate handling of the cascade operation is not yet done. (as I know the other light-weight open source tool called sql2java handles this pretty well anyway)

I can see the road map to achieve this purpose is to:

middlegen the hbm mapping file based on db schema --> hbm2java generates persistence java classes

and middlegen can be also used to achieve the other code generation purposes.

The crucial bit is on MiddleGen side -- to see how well the Hibernate plugin for middlegen is going to perform in handling the mappings of relationships persistence.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 06, 2004 12:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
What is it your looking for with the cascades options?

Middlegen can set it globally, eg, cascade='save-update' using the Ant script.
If you want to set it on the relationship on each of the relationship using the GUI then its a different matter. Looking at the sql2java web site there is almost no options in dealing with the code generation, relationship types etc that I can see. Only JDBC driver, Table collection filter. It might be more powerfull than it indicates but I could find it from the limited docs or the example.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 06, 2004 2:45 am 
Newbie

Joined: Wed Nov 03, 2004 6:41 pm
Posts: 12
Location: Canberra/Sydney Australia
The cascade feature would be bascially crucial to handle relationships among perent-children style entities, but by looking at the middlegen website one of the messages I've got from there was "...Currently setting the cascading options on the relationships in the GUI is not possible (possibly will be in the near future) so you can either post process the hbm files to select the appropriate setting or use the appropriate hibernate plugin attributes....", and since this is only the message being shown regarding to the cascade relationship on the middlegen website, I maybe misunderstood what it's trying to say there...

Anyhow, now I have enough the information on two types of tools and I think what I need to do next is to give them a play and do the comparison on how well they will perform.

Yeah of course from the upcoming experiment I do really hope middlegen hibernate extension will be doing well as it seems that it's currently the only tool providing this sort of plugin for hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 06, 2004 7:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I am guilty of letting the Hibernate wiki page get out of date in places. I will update it later today. This earlier limitation for setting a Cascading option (globally) is no longer present.


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.