Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serialized Bean with Hibernate

 
Diane Weaver
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Need advice on the best way to implement the following using Hibernate:

Kitten
String id
String catId

Cat
String id
Set<Kitten> kittens
String hairColor

PendingCat
String id
String serializedCat
String status


Each is a bean (POJO) persisted using Hibernate.

Details:
The PendingCat table is used to store incomplete records. Database constraints would not allow them to be stored in the Cat table.

The goal:
Retrieve a PendingCat record from the database, deserialize it to create an instance of a Cat, make updates, then either update the PendingCat table (if validation fails) or create a new Cat record (when validation passes).

The attempt:
Add a transient Cat property to the PendingCat bean. In the set method of the Cat property serialize it and update the serializedCat property. In the set method of the serializedCat property deserialize it and update the Cat property. (Updates are done by updating the private variable, not calling the set methods and creating an infinite loop.) Serializing and deserializing is done using java.beans.XMLEncoder and java.beans.XMLDecoder.

The problem:
When the Cat instance is created by deserializing the Kitten set is a PersistentSet. As soon as it is accessed the infamous LazyInitializationException is thrown. I haven't been able to attach it to a session because I get the "an object with that ID already exists" error. It seems like somehow I have a partially attached object. Any ideas (other than eliminating serialization)?
 
Diane Weaver
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case anyone else is looking for a solution to this, I've implemented Giliead. From their site:

Gilead stands for Generic Light Entity Adapter

It permits you to send Persistent entities (and especially the partially loaded ones) outside the JVM (GWT, Flex, Web-Services, ...) without pain.

http://noon.gilead.free.fr/gilead/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic