-->
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: Making an entity read-only?
PostPosted: Tue Aug 26, 2008 6:27 pm 
Newbie

Joined: Tue Aug 26, 2008 6:05 pm
Posts: 6
[b]Hibernate version: 3 + annotations[/b]

I have two projects working against a database. One project maps to a table and can write to it. The second project should map to some fields of the same table, but be read-only. Is it possible to guarantee that the entity created in the second project will never attempt an insert/update/delete?

Additionally the entity is a subclass, does this complicate things?

Ideally I'd like to acheive this via annotations. If not, then I'll have to create my own and check it in my HibernateUtil.create()/update()/delete(). I have no control over the DB so I cannot make a view.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2008 5:11 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

does each of the projects have its own entity mapping? If so it should be easy. In case you are trying to reuse the mappings it will be harder.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2008 4:33 pm 
Newbie

Joined: Tue Aug 26, 2008 6:05 pm
Posts: 6
Yes, each project has it's own entity mapping. We can even have multiple per project since yesterday. I created a solution yesterday where I can register multiple mappings for a project:

e.g. HibernateUtils.registerMapping(DomainObject1.class,"hibernate-domain1.cfg.xml");

and the HibernateUtil will look up the correct factory for each class.
e.g.
HibernateUtils.findAll(DomainObject1.class,"status",ACTIVE);

But these don't stop someone from accidentally creating a DomainObject1


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2008 8:42 pm 
Newbie

Joined: Thu May 31, 2007 3:27 am
Posts: 11
Look for the attribute "mutable" for the "class" element in the mapping file


http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#mapping-declaration-class


Quote:
"mutable (optional, defaults to true): Specifies that instances of the class are (not) mutable. "


for the individual property, there are the attributes "update" and "insert" that control if the property can be modified on an insert or an update respectively


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2008 9:21 pm 
Newbie

Joined: Tue Aug 26, 2008 6:05 pm
Posts: 6
Thanks that looks like hibernate can do what I'm after. I didn't find an @Class annotation, so I guess I'm supposed to do something in the cfg.xml. I'll have a play later.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2008 4:49 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
for the annotations you can use @Immutable

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2008 4:08 pm 
Newbie

Joined: Tue Aug 26, 2008 6:05 pm
Posts: 6
Excellent, thanks.


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.