Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Serialized Bean with Hibernate

 
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/
 
Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic