-->
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.  [ 10 posts ] 
Author Message
 Post subject: EJB3, serialisation of detached entities
PostPosted: Wed Feb 22, 2006 7:10 pm 
Newbie

Joined: Wed Feb 22, 2006 6:59 pm
Posts: 4
Hallo,

Why are detached entities with lazy related collections not converted to their "origin" Class structure, but converted to another class structure ? The conversion of Collection to PersistentSet gives problems with serialisation of the detached objects. Is this a bug or feature in hibernate / EJB3 ?!? My session is closed, so the object is detached.

Thanks !


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 01, 2006 11:12 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This is a feature, otherwise we woudn't know what to update and what not to update during reattachment

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 06, 2006 6:30 pm 
Newbie

Joined: Wed Feb 22, 2006 6:59 pm
Posts: 4
But what is the correct way to return a detached entity to a remote client ?!? The only way now is to set all the relations to null :

entity.setChildren(null)

otherwise the serialisation of the related collections etc. throws an exception. This is not a nice way to achieve the serialisation is it ?!? Are there standards for this pattern ?

Thanks !


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 07, 2006 11:53 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Have Hibernate jar on the client side

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 12:21 pm 
Newbie

Joined: Wed Feb 22, 2006 6:59 pm
Posts: 4
Dear emmanuel,

Thanks for your thoughts !

The exception is thrown on the server side while serializing the entity. I'm using Adobe Flex 2.0 with Remote Java objects. The flash client call a remote Java object on the flex server (JBoss) and serialises the result to it's own format for transporting the Java object to the Flash client.

So the problem is that the flex server cannot serialise the java object because of the "PersistentSet" attribute type.

The case is very common I think :

1) With an ejbql query an entity is retrieved without the related objects (lazy !)
2) The entity is detached for returning to a remote client. Not a Java client in this case.
3) The detached object is serialised by the server container for transport to the client.

The only solution is now to set all the relationships of the detached entity to NULL.

I think there should be a simple pattern for this case ?!?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 10:18 am 
Beginner
Beginner

Joined: Wed Apr 13, 2005 10:34 am
Posts: 38
Just a thought:
- use the access type "field" for those classes
- change the getter to return a new collection filled with the entries from the persistent collection
- change the setter to clear() the persistent Collection and add all entries from the given collection


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 8:40 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
h.b. wrote:
Just a thought:
- use the access type "field" for those classes
- change the getter to return a new collection filled with the entries from the persistent collection
- change the setter to clear() the persistent Collection and add all entries from the given collection


That would prevent you to merge() serialized entities. All lazy collection would be nullified in DB

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 15, 2006 8:05 am 
Beginner
Beginner

Joined: Wed Apr 13, 2005 10:34 am
Posts: 38
In the meantime I thought it's not a good idea anyway, because the Collection.addAll()-Method would iterate the (possibly lazy) persistent collection and result in a well known LazyInitializationException during serialization.

I did not quite understand, why it would break merge() but this is nearly OT.
;-)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 15, 2006 3:56 pm 
Newbie

Joined: Wed Feb 22, 2006 6:59 pm
Posts: 4
I thought the (easy) detachment and returning of detached entities was part of the new EJB 3 specification, but I think this is not the case ?!?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 15, 2006 7:37 pm 
Beginner
Beginner

Joined: Wed Apr 13, 2005 10:34 am
Posts: 38
It indeed is part of the spec and it actually works quite fine.
But Flex's special Serializer is not part of the EJB spec.

Maybe you can add custom serializer classes to Flex for the persistent collection types. I did that for an XML serializer (XStream) a while ago.

Good luck.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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.