-->
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.  [ 7 posts ] 
Author Message
 Post subject: how can I restrict updates to a table?
PostPosted: Thu Jun 15, 2006 10:55 pm 
Newbie

Joined: Mon Jun 12, 2006 7:25 pm
Posts: 7
Hi,

I have a table and I only want to allow inserts and reads from it. at the application layer. I want to prevent row updates and deletes. I want the restriction at the application layer because I will allow some other applications to perform updates or deletes.

Is there anyway to define such restriction in the hibernate mapping file for a given persistent class? Can hibernate throw an exception when the application tries to commit an update or delete operation on a persistent object?

Thanks,
Ali


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 16, 2006 12:07 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
There are many different ways of doing this.
  1. You could write PreUpdate and PreDelete event listeners: see ref docs section 12.2, "Event system".
  2. You could write an Interceptor and implement the onDelete and onSave methods. This is in section 12.1. "Interceptors">
  3. You could add update="false" to all properties, associations and collections in the class' mapping. Note that this will be a silent no-update/delete, you won't get an exception.
  4. You could add update="false" to all collections/associations to this class from other mappings. As before, you won't get a warning when an update is attempted, it just won't happen.
There are upsides and downsides to each of these choices. Read the docs to find out which one (or which combination) is right for you.

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


Top
 Profile  
 
 Post subject: update="false" - where you specify that?
PostPosted: Wed Apr 25, 2007 10:55 pm 
Newbie

Joined: Wed Apr 25, 2007 10:29 pm
Posts: 5
tenwit wrote:
* You could add update="false" to all properties, associations and collections in the class' mapping. Note that this will be a silent no-update/delete, you won't get an exception.
* You could add update="false" to all collections/associations to this class from other mappings. As before, you won't get a warning when an update is attempted, it just won't happen.


Maybe I am being incredibly dumb/blind - but I dont see any way to set update="false" on collections....

Can anyone confirm that Im either correct or a dumbass?

I really want to suppress the "update" of collections when I update a previously detached object. I know those collections will never change after the initial save....

Cheers,
Nick


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 25, 2007 11:44 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You are correct. I was misremembering the addition of the mutable attribute to collections. insert/update attributes has never been added to collections.

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 25, 2007 11:48 pm 
Newbie

Joined: Wed Apr 25, 2007 10:29 pm
Posts: 5
tenwit wrote:
You are correct. I was misremembering the addition of the mutable attribute to collections. insert/update attributes has never been added to collections.


Ok.. thats that settled.

(TBH though, Id have preferred to be found to be a dumbass ... Id kinda like this tuning)

I take it, the absence of update/insert specification for collections is because its nasty? (or is it, in fact planned?)

Cheers.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 25, 2007 11:58 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
More likely, noone has requested it. If mutable="false" is possible, and mutable="false" is the same as insert="false" update="false", then I can see no reason not to allow insert/update attributes.

Search JIRA for a development request. I suspect that you won't find one.

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 01, 2007 9:10 am 
Newbie

Joined: Wed Apr 25, 2007 10:29 pm
Posts: 5
I might add one then :-)


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