-->
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.  [ 5 posts ] 
Author Message
 Post subject: insert-only table
PostPosted: Mon Feb 02, 2009 6:41 pm 
Newbie

Joined: Mon Feb 02, 2009 6:36 pm
Posts: 1
I'm using MSSQL 2005 and Hibernate 3.1.3

I have several tables that I would like to be insert-only. By that I mean that I would like to be able to retrieve data from the tables (a nested entity tree) but when a change is made that rather than update the rows new inserts should be done.

What is the best way to do this?

Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 9:33 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Put mutable="false" in the class element of the mapping. This prevents updates. You can also put update="false" on all the properties, etc.

Everything else will have to be done in business logic. For example, you could have a findForUpdate method that finds the appropriate entity and creates a new transient object from it. When the new object is saved, you'll get an insert. Alternatively, you could have a save method that creates the new object. If the object is simple and has no associations (or if you hydrate everything in advance), you could evict the object from the session, set the ID to the unsaved value (usually null), and save it again.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2009 4:13 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
It seems that you want to have some kind of history of your entities? Have a look at Envers, which will also be a part of hibernate core in the next hibernate release.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2009 4:15 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
double post.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2009 4:17 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
double post again, don't know why...

_________________
-----------------
Need advanced help? http://www.viada.eu


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