-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Save mapped object to a different table?
PostPosted: Wed Jul 02, 2008 7:24 pm 
Newbie

Joined: Wed Jul 02, 2008 7:18 pm
Posts: 1
Hi guys,

I have an entity mapped to a certain table. I have a tool that looks for expired objects based on some date and I want to essentially "move" the entry to an archive table. This involves (I think) writing the object to the archive table and deleting it from the original one.

Entities are mapped to a table in Hibernate (I use the @Table annotation). Is it possible to just set the table to the archive table and simply call save() or is it more complex that that? Any other, better ways to do this in Hibernate? Is it even possible?

Many thanks for your help.

Nick.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 1:21 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Quote:
This involves (I think) writing the object to the archive table and deleting it from the original one.


Yeah, that's about it.

Sometimes ETL tools are better at these types of processes, but it's certainly doable with Hibernate.

Simply load the record/object. Delete the record from the one table, perhaps pass the entity to a constructor that creates a copy, but of the other object table, and then save to the new table. Do it all within the scope of a transaction and you'll get your unit of work/ACID properties that you'll want.

You may need to do an evict or something during the copy stage - not sure. This little tutorial on How Hibernate Works might help answer some questions on what to do when you get into the guts of your app:

http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=07howhibernateworks

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: Save mapped object to a different table?
PostPosted: Tue Oct 05, 2010 10:12 am 
Beginner
Beginner

Joined: Sat Mar 13, 2004 4:00 pm
Posts: 32
Has there been any added support to Hibernate to help with this issue or is "archiving" of data still needed to be done as suggested in this thread.

thanks,

Rich


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 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.