-->
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.  [ 1 post ] 
Author Message
 Post subject: Design flaw within PersistentList
PostPosted: Fri Nov 14, 2008 10:33 am 
Newbie

Joined: Tue Mar 04, 2008 10:37 am
Posts: 6
Hi everyone.

I am using Hibernate version: 3.2.6.ga.

As I understand (and saw while debugging) Hibernate uses PeristenCollections to represent persistent properties. In these collections there is a field called owner holding the owner of the collection. This leads to problems when the collection elements implement the serializable interface and are allowed be serialized but the owner of the list isn't.

We have a 3-thier model where most of the server side classes are not allowed to be modified directly by the client ( we use transfer objects) and therefore are not implementing the serializable interface to guarantee this but there are some exceptions.

Lets have a look at an example where the hibernate way to handle persistent collections causes an not serializable exception.




Code:
@Entity
public class Test{
@OneToMany
List<TestElements> testElements= new ArrayList<TestElements>();
...
}
@Entity
public class TestElements implements Serializable{
...
}


When we now go to serialize the testElements list an Exception will be thrown because the PersistentList used by hibernate to represent testElements contains, in the owner field, the class Test which doesn't implement the serializable interface and therefore cannot be serialized.

As a workaround you can simply make a deep copy of your objects before serializing.

I think this is a major design flaw within Hibernate. I am looking forward to hear your opinion about it.

Cheers Tim


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.