-->
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: [Announce] New hibernate source code generator tool
PostPosted: Wed Dec 19, 2007 6:15 am 
Newbie

Joined: Tue Dec 18, 2007 2:06 pm
Posts: 9
Apologies for not posting to the right forum on my first try:

http://forum.hibernate.org/viewtopic.php?t=982255


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 19, 2007 2:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
(posting here as an answer instead)

I'm referring to Hibernate tools not hibernate synchronizer.

Of all the features you mention only enum is not supported (how do you define what is an enum based on the database metadata?)

I don't know what you mean by inheritance; again how do you define it ? I couldn't find any docs on it.

All the other things you mention annotations, complex joins etc. is part of hibernate tools so if you could tell me what is so special compared to the uptodate hibernate tools instead of hibernate synchronizer which have not been maintained in years then it would be great ;)

About contributions then you are using GPL meaning I can't really see my self contributing to it since it prevents me (and you) from including it into e.g. Eclipse as a plugin.

LGPL would have been much more sensible.

Besides we have a whole range of other functionallity in hibernate tools which is not covered by your tooling (as far as I can see) e.g. hbm.xml support and code generation from existing classes (not forcing usage of reveng) so I'm more curious in identifying what is missing in hibernate tools (if any) of your features.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 19, 2007 3:38 pm 
Newbie

Joined: Tue Dec 18, 2007 2:06 pm
Posts: 9
max wrote:
(posting here as an answer instead)

I'm referring to Hibernate tools not hibernate synchronizer.

Of all the features you mention only enum is not supported (how do you define what is an enum based on the database metadata?)



I use the metadata, but then again I only support MySQL for now which makes handling this easy (though postgreSQL enums are coming in 8.3).

max wrote:
I don't know what you mean by inheritance; again how do you define it ? I couldn't find any docs on it.


Please educate me on the proper term to use. I define "inheritence" whenever I have exactly one Primary Foreign Key from one table to the next, thus making a class extend another.

max wrote:
All the other things you mention annotations, complex joins etc. is part of hibernate tools so if you could tell me what is so special compared to the uptodate hibernate tools instead of hibernate synchronizer which have not been maintained in years then it would be great ;)


I'm not knowledgeable enough on hibernate tools to answer that specific question; what I can do is point out the annoying things we found in the hibernate synchronizer, namely: enums were completely unsupported, used hbm files instead of annotations, no unit tests generated, no spring support, bloated code (ok, Joe meant this as a feature in that a core set of code would not change, but our developers hated it and started to "clean" up the code). Also, due to missing unsigned types in Java, an UNSIGNED INTEGER in the mySQL DB was being mapped as Integer in the java world which of course is not a clean mapping. Therefore using the hibernate synchronizer we were going back changing all Integers to Long (and so on). Can you confirm if this is at all necessary in hibernate?

max wrote:
About contributions then you are using GPL meaning I can't really see my self contributing to it since it prevents me (and you) from including it into e.g. Eclipse as a plugin.

LGPL would have been much more sensible.


That was my failing, and I'll take steps to switch the license to LGPL as soon as possible.

max wrote:
Besides we have a whole range of other functionallity in hibernate tools which is not covered by your tooling (as far as I can see) e.g. hbm.xml support and code generation from existing classes (not forcing usage of reveng) so I'm more curious in identifying what is missing in hibernate tools (if any) of your features.


The number #1 feature I see missing (at least from a cursor look at the docs) is a unit test case which tests all the generated code (+ having a data populator to prefill an object is nice). The hard part about this is determining all the table dependencies and dealing with loops but then again all the information is there to process. Spring configs would also be nice but not necessary.

Max, please do understand that I do respect your work and my release in no way is trying to "complete" or replace your efforts. It's merely another jab at the problem. It's OK if you choose to completely ignore it, meanwhile it has made at least one batch of users happy - my company. If nothing else comes from it, so be it, the company has already paid for the effort and is perfectly happy with the results. If someone else finds it useful, kudos to them, we're asking for nothing in return. Meanwhile we had some spin-offs: I learnt hibernate much much more and a hibernate bug was found (and patch submitted: http://opensource.atlassian.com/project ... l-tabpanel)

I'm no Hibernate expert and, judging by your posts, I do believe you're very knowledgeable so please don't take offence at my effort. If it was wasted energy, well it was mine to waste. Additionally, no animals were harmed during the making of the project :-)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 20, 2007 4:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
HbnpojoAuth wrote:
max wrote:
Of all the features you mention only enum is not supported (how do you define what is an enum based on the database metadata?)


I use the metadata, but then again I only support MySQL for now which makes handling this easy (though postgreSQL enums are coming in 8.3).


Ok, so I assume this is some native mysql metadata you look up or are you using plain jdbc metadata?

Quote:
max wrote:
I don't know what you mean by inheritance; again how do you define it ? I couldn't find any docs on it.


Please educate me on the proper term to use. I define "inheritence" whenever I have exactly one Primary Foreign Key from one table to the next, thus making a class extend another.


ah ok - so you translate one-to-one's as inheritance. I guess that could be an option.

Quote:
max wrote:
All the other things you mention annotations, complex joins etc. is part of hibernate tools so if you could tell me what is so special compared to the uptodate hibernate tools instead of hibernate synchronizer which have not been maintained in years then it would be great ;)


I'm not knowledgeable enough on hibernate tools to answer that specific question; what I can do is point out the annoying things we found in the hibernate synchronizer,


namely: enums were completely unsupported,

[/quote]

Hibernate tools does not have that for one (good?) reason, namely that afaik I it is not supported by jdbc metadata to get this info....if that is incorrect then I would love to know how ;)

Quote:
used hbm files instead of annotations,


yup, hibernate tools had this for ages.

Quote:
no unit tests generated,


you should have fixed our datagen jira issue and it would have been available in hibernate tools then ;)

Quote:
no spring support


hibernate tools can be customized for that (others done that)

Quote:
, bloated code (ok, Joe meant this as a feature in that a core set of code would not change, but our developers hated it and started to "clean" up the code).


well that is why you have contributions to fix the bloat or templates to allow users to customize it.

Quote:
Also, due to missing unsigned types in Java, an UNSIGNED INTEGER in the mySQL DB was being mapped as Integer in the java world which of course is not a clean mapping. Therefore using the hibernate synchronizer we were going back changing all Integers to Long (and so on). Can you confirm if this is at all necessary in hibernate?


You mean in hibernate tools ? then we got some afaik pretty good defaults but if you want to control the mapping when doing reveng you just specify that for a given jdbc type you want some specific hibernate type.


Quote:
max wrote:
Besides we have a whole range of other functionallity in hibernate tools which is not covered by your tooling (as far as I can see) e.g. hbm.xml support and code generation from existing classes (not forcing usage of reveng) so I'm more curious in identifying what is missing in hibernate tools (if any) of your features.


The number #1 feature I see missing (at least from a cursor look at the docs) is a unit test case which tests all the generated code (+ having a data populator to prefill an object is nice). The hard part about this is determining all the table dependencies and dealing with loops but then again all the information is there to process.


yup - we have had http://opensource.atlassian.com/project ... se/HBX-215 sitting and waiting for someone to pick it up and do exactly this....;)

Quote:
Spring configs would also be nice but not necessary.


that would be something that someone could add on top yes.

Quote:
Max, please do understand that I do respect your work and my release in no way is trying to "complete" or replace your efforts. It's merely another jab at the problem. It's OK if you choose to completely ignore it,


I understand that, I'm just surprised to see about 1 of these attempts every 2-3 months and they always completely ignore that we have 90% of what these projects are redoing in hibernate tools and thus contributing or builiding on top of hibernate tools would be much more sensible IMO.

I fully understand your situation and respect that you actually created something that solves your problem - i'm just trying to understand why everyone wants to redo this again and again and again instead of expanding on what exists ...;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 02, 2008 5:58 am 
Newbie

Joined: Tue Dec 18, 2007 2:06 pm
Posts: 9
max wrote:
HbnpojoAuth wrote:
max wrote:
Of all the features you mention only enum is not supported (how do you define what is an enum based on the database metadata?)


I use the metadata, but then again I only support MySQL for now which makes handling this easy (though postgreSQL enums are coming in 8.3).


Ok, so I assume this is some native mysql metadata you look up or are you using plain jdbc metadata?



Apologies for the late reply, for I have been sick throughout the entire festive season.

Regarding mysql enum metadata, the connection driver sucks, you have to use dbmd.getColumns() followed by fieldNames.getString("TYPE_NAME") to determine it's an ENUM, calling getColumnTypeName() returns "String" instead of the right "ENUM".

Thereafter, the following code will fetch all possible enum values:

/**
* Given an enum, it returns all possible values of it. wasScrubbed will be true if enums didn't match completely
* @param conn
* @param tblName
* @param fieldName
* @param wasScrubbed
* @return An arraylist of enum values
* @throws SQLException
**/
public static String[] getEnumValues(final Connection conn, final String tblName, final String fieldName, Boolean[] wasScrubbed) throws SQLException {
Statement stat = null;
ResultSet rs = null;
TreeSet<String> enumset = new TreeSet<String>();
try{
stat = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
rs = stat.executeQuery(String.format("SHOW COLUMNS FROM %s LIKE '%s'", tblName, fieldName));

rs.next();

String enumTypes=rs.getString("type");

enumTypes=enumTypes.substring(enumTypes.indexOf("(") + 1, enumTypes.length() - 1);

String[] result = enumTypes.replaceAll("'", "").split(",");
wasScrubbed[0]=false;
for (int i=0; i < result.length; i++){
String res = cleanEnum(result[i], enumset, i, wasScrubbed);
result[i]=res;

}

return result;
}finally{
if (stat != null){
stat.close();
}
if (rs != null){
rs.close();
}

}
}


There's some extra cleanup routines ("cleanEnum") to make sure enums like:

+01:00, +02:00

are cleaned up to have a valid Java identifier name.



max wrote:
All the other things you mention annotations, complex joins etc. is part of hibernate tools so if you could tell me what is so special compared to the uptodate hibernate tools instead of hibernate synchronizer which have not been maintained in years then it would be great ;)


Quote:
namely: enums were completely unsupported,


Quote:
Hibernate tools does not have that for one (good?) reason, namely that afaik I it is not supported by jdbc metadata to get this info....if that is incorrect then I would love to know how ;)


Feel free to copy my code over to yours, though it looks pretty DB specific thanks to poor JDBC support (eg Postgres is about to introduce proper enum support now but it's pretty different to Mysql - one enum type can be shared across tables).



Quote:
no unit tests generated,

Quote:
you should have fixed our datagen jira issue and it would have been available in hibernate tools then ;)



We haven't got much code that's worth ripping, what we've got to give you as a headstart is a package which generates random data (eg generateRandomString, generateRandomInteger, etc). The rest is probably too specific to your tool to extract. Again feel free to copy it over as an initial starting point (it should have no dependencies on the rest of the code).


Also, would you be so kind to clarify if multiple schema support is present in Hibernate tools? (I mean also bringing in objects representing tables that are in schemas outside of the ones referenced by the default schema). This was one major show-stopper for us in the Joe's Hibernate Synchronizer.

Best (belated) wishes for the new year


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 02, 2008 6:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
HbnpojoAuth wrote:
Feel free to copy my code over to yours, though it looks pretty DB specific thanks to poor JDBC support (eg Postgres is about to introduce proper enum support now but it's pretty different to Mysql - one enum type can be shared across tables).


cool - we should be able to add this as something our MetaDataDialect can optionally handle based on the underlying db.

Quote:
Also, would you be so kind to clarify if multiple schema support is present in Hibernate tools? (I mean also bringing in objects representing tables that are in schemas outside of the ones referenced by the default schema). This was one major show-stopper for us in the Joe's Hibernate Synchronizer.


Yes - hibernate tools were born with multischema support.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re:
PostPosted: Tue Nov 17, 2009 10:49 am 
Beginner
Beginner

Joined: Tue Feb 03, 2009 4:33 pm
Posts: 21
max wrote:
cool - we should be able to add this as something our MetaDataDialect can optionally handle based on the underlying db.


Hi Max,

Has there been any movement on MySQL enum support in REVENG? I know it's been a while, so maybe this is already supprted. If so, can you point me at an example that shows how to configure hbm2java to use this capability (currently, my setup is generating java String fields instead of Enums...)

thanks!


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.