• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementing object versioning with Hibernate

 
Avner Levy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm trying to implement multi-version object store with Hibernate. The way the system works is storing a new row each time an object is changed and flag the latest object version. This way when you query for all cats I add to the query where clause "and last=true" and only the latest version of each object is fetched.
There are two places where I'm having problems.
One is how to implement the "remove" API. When an object is deleted I don't really delete it but I flag it as deleted. Since the object can have some sub-objects like addresses for each cat stored, I need to find a way to cascade the deletion flagging to all relevant sub-objects.
Another problem is all the relationships between objects which is managed by Hibernate.
Example:
If I have a cat with few address (one2many) and I change the cat object, what I actually do is inserting a new cat and flagging it as the latest while removing the "latest" flag from the previous object. Since all references are done through IDs, all addresses are referencing now the old version of the object instead of the new one.
If anyone have ideas how such issues can be solved it will be great.

Thanks in advance,
Tim
 
mahaveerchand jain
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure on what you mean by deletion flagging . But to cascade the deletion you can use the following


cascade="delete" tells Hibernate to navigate the association and delete persistent
instances when an object is passed to delete().


cascade="all-delete-orphan" means the same as cascade="all" but, in addition,
Hibernate deletes any persistent entity instance that has been removed
(dereferenced) from the association (for example, from a collection).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic