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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

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.
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!
    Bookmark Topic Watch Topic
  • New Topic