Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Best pattern for storing multiple versions of the entity?
PostPosted: Fri Oct 02, 2009 10:17 pm 
Regular
Regular

Joined: Tue May 12, 2009 6:08 am
Posts: 92
What is the best pattern for storing multiple versions of the same entity? Two tables? One for the entity X and another to store all the versioned data?

I've played around with the <version> mapping, and I don't think this does what I want it to do. I think it's used for something entirely differently.

I guess what I want to do is something like a version control system... where I keep track of every snapshot that ever existed for the entity, and thus have the ability to compare between the various versions.

My best guess is a 2 table solution, or a primary key with the entity_id and the version_id, and then I increment the version every time and also insert rather than update.

Is there something a bit more framework-y for this though? Transparency would be great.


Top
 Profile  
 
 Post subject: Re: Best pattern for storing multiple versions of the entity?
PostPosted: Fri Oct 02, 2009 10:45 pm 
Regular
Regular

Joined: Mon Sep 29, 2003 9:39 am
Posts: 67
If you have one table, a second archive table might make sense.

If you're looking for a framework-y way hook, there are several ways: JPA-style, Events or Interceptors.

http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html/listeners.html
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/events.html

HIA describes this in 12.3.2 as well.


Top
 Profile  
 
 Post subject: Re: Best pattern for storing multiple versions of the entity?
PostPosted: Sun Oct 04, 2009 9:52 pm 
Regular
Regular

Joined: Tue May 12, 2009 6:08 am
Posts: 92
I guess a second table looks to be the best option. I can always archive the last version, that way I never have to muck with the current version. It will work like every other table.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.