-->
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: Hibernate 3 Migration Guide: Missing Information
PostPosted: Mon Jun 06, 2005 7:32 am 
Newbie

Joined: Thu Feb 17, 2005 5:19 am
Posts: 8
Last week we tried to switch from Hibernate 2 to Hibernate 3. After reading the migration guide it didn't seem that much of a problem.

Seems we were wrong in that assumption. We've run into lots of problems (and we are not finished yet...), and I'm sure we'd have stayed with Hibernate 2 if we knew beforehand.

Anyway, here is a list of the some of the problems we encountered. Maybe some of that should be put into the migration guide. Ather points may be just misunderstanding on our side. I'd be grateful for any information about this.

Some information about the application scenario: Our application has about 40 persistent classes. We define each class using a .hbm.xml file and let Hibernate create the Java files and the SQL DDL.

Most, but not all problems are related to the hbm2java code generation tool.

1. Hibernate 3 no longer creates hashCode() and equals() methods.
In Hibernate 2 you could use the meta tag "implement-equals" to create equals() and hashcode(). Additional infomation in the property definition specified which properties were to be used in these methods.
Hibernate 3 apparently no longer supports the "implement-equals" meta tag. equals() and hashCode() must be implemented manually.

2. In Hibernate 2 the Java code generated by Hibernate implemented boolean attributes that were not nullable as boolean (the primitive type). Hibernate 3 creates these attributes as Boolean objects. An additional complication is the fact that the Boolean attributes are initialized with null. As a result of this change all objects initialization must be changed to set these attributes (where in the past the default value of false might have been sufficient), and all calls to the getter/setter methods must be changed to deal with Boolean objects instead of boolean values.

3. As a related point: The getter methods to boolean attributes used to be named isAttribute(), now the hbm2java tools creates getAttribute() instead (where "Attribute" is the attribute name).

4. The Hibernate 2 hbm2java tool used to create four constructors for each class: one default constructor, one with only the ID as parameter, one taking all not nullable attributes, and one with all attributes. The code generated by hibernate 3 only creates the default constructor and the one taking the ID. All calls using one of the other constructors must be changed.

5. In Hibernate 2 you had the *option* to use a proxy class for lazy loading of many-to-one and one-to-one associations. This was well documented, as was the fact that this appoach was highly problematic if you were using polymorphic classes (unless you defined interfaces for all your persistent classes). Hibernate 3 uses this problematic approach now by default, even for direct loading. Now, if I ask hibernate to load a specific inctance of one class (by specifying its ID) hibernate will create a proxy, which can *not* be casted to the respective subclass represented by the object. This means if the are using polymorphic classes you must create interfaces (manually) for all classes, you must use these interfaces in all references to the objects, and you must modify the hbm.xml files to use these interfaces as proxies. All that, even if you don't use lazy loading of many-to-one or one-to-one associations.


That's all I can think of the top of my head right now. I'll add to this if we find more problems.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 06, 2005 7:52 am 
Newbie

Joined: Thu Feb 17, 2005 5:19 am
Posts: 8
I just discovered that the problem described in 5. can be avoided by specifying default-lazy="true" in the hbm.xml file.

Phew. One big problem solved! :-)
However, it should be mentioned more explicitely in the migration guide.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 11, 2005 12:06 pm 
Beginner
Beginner

Joined: Fri Aug 20, 2004 3:45 pm
Posts: 22
Location: Florence - ITALY
About point 2, I had post a similar problem for Integer type. I suppose that the problem of "primitive type of not-nullable property" it is involved all primitive type.

I don't understand why this useful feature, who were present in 2.x version of hibernate tool it has been removed.

I don't think this is a bug.


Gianni


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 11, 2005 3:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you seem to be talking mostly about the hbm2java codegenertaor and not so much about hibernate core.

Did you try and use the latest version of hibernate tolls - alpha 4 ?

The tools have been rewritten to be more consistent and some of you issues I simply cannot reproduce (like the is/get for boolean)

-max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 13, 2005 5:09 am 
Newbie

Joined: Thu Feb 17, 2005 5:19 am
Posts: 8
I used alpha 3 of the hibernate tools (checked out from CVS. At that time only alpha 1 of the tols was released.

I will try latest version of the tools later today.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 13, 2005 5:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
gabby wrote:
I don't think this is a bug.


So, whats the problem ? ;)

http://opensource.atlassian.com/project ... se/HBX-286

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 13, 2005 10:05 am 
Newbie

Joined: Thu Feb 17, 2005 5:19 am
Posts: 8
OK, I tried the alpha 4 version of hbm2java.

Except for a small bug fix in a comment it seems to generate exactly the same code as the alpha 3 version.

Not nullable boolean attributes are still Boolean, and the getter method still start with "get" instead of "is".

Max, you say you can't reproduce the get/is problem. Are the boolean attributes in your case also created as Boolean objects?

Here is an example of an attribute definition we use:

<property name="disabled" column="disabled" type="boolean" not-null="true"/>

Any obvious error here on our part?


regards, Thomas


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.