-->
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.  [ 6 posts ] 
Author Message
 Post subject: Mapping a database view using Hibernate
PostPosted: Sun Dec 19, 2004 6:34 am 
Newbie

Joined: Thu Nov 18, 2004 12:32 pm
Posts: 8
Location: UK (Newcastle upon Tyne)
I need to map a view in the DB to a Hibernate object. Everything seems as straightforward as mapping a normal table. However I want to prevent updates to this Bean class.

The attribute "usage=read-only" talks about caches. There seems to nothing at the property level of the Bean that says read-only.

All my bean access is though a Session facade. But I wish I can set up a guard against updates so that future programmers or API users would be stopped from trying it by accident.

Not a show stopper but some thoughts would be useful. Many thanks.


Cheers
-raj

_________________
- cowboy maybe, but an injun at heart


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 19, 2004 6:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
from docs:

Code:
mutable="false", may not be updated or deleted by the application


and to totally prevent inserts, i don't think we have other means than install an interceptor and let it complain if certain classes are being passed to it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 19, 2004 11:03 am 
Regular
Regular

Joined: Thu Oct 07, 2004 4:45 pm
Posts: 92
Name the persistent class something like ImmutableFooBar and don't expose any setters on it. If future programmers in your organization don't get the hint, I think it's a lost cause. ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 19, 2004 11:05 am 
Regular
Regular

Joined: Thu Oct 07, 2004 4:45 pm
Posts: 92
Of course, you must also then map the columns directly to object fields instead of property setters.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 20, 2004 6:22 am 
Newbie

Joined: Thu Nov 18, 2004 12:32 pm
Posts: 8
Location: UK (Newcastle upon Tyne)
rhasselbaum wrote:
Of course, you must also then map the columns directly to object fields instead of property setters.


Aah, that was the bit I was missing. I did try removing the setters but got error with my ear loaded into JBoss.

Of course, that still leaves the problem of inserts which has to be handled by intercepting the call to the Bean as stated above. Any implementation example anywhere?

Cheers
-raj

_________________
- cowboy maybe, but an injun at heart


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 20, 2004 9:39 am 
Regular
Regular

Joined: Thu Oct 07, 2004 4:45 pm
Posts: 92
Another approach: If the ID field has a not-null constraint, you could map it to an "assigned" ID generator in Hibernate. Since there's no way for code to set the ID, any attempt to insert a new row should generate a constraint violation.

Haven't tried this myself, but can't think of a reason it won't work.


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