• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Serialized Bean with Hibernate

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:

String id
String catId

String id
Set<Kitten> kittens
String hairColor

String id
String serializedCat
String status

Each is a bean (POJO) persisted using Hibernate.

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
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.

Too many men are afraid of being fools - Henry Ford. Foolish tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!