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: Read-only property
PostPosted: Wed Mar 05, 2008 12:39 pm 
Newbie

Joined: Sun Jun 10, 2007 5:32 pm
Posts: 8
Location: Gothenburg
Hi!

I have a derived read only property in a class that I want NHibernate to insert/update to the database, but I don't want NHibernate to set the property when the object is initialized since the property is set internally by the class when another property is set.

Is there a way to do this, other than modifying the domain model?

I have looked at IInterceptor and IUserType but haven't found a way.

Help would be very much appreciated.

// Peter


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 05, 2008 3:43 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Maybe I get you wrong, but if the property setting your read only property is mapped, why do you need to map your read only property at all ? It should be set when the other property is set during object instantiation.


Or you could change the getter of the derived property to get the current value and use an empty setter.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 05, 2008 8:01 pm 
Newbie

Joined: Sun Jun 10, 2007 5:32 pm
Posts: 8
Location: Gothenburg
Hi!

You got me right.

Some properties in the class are populated from Active Directory, some from the database. One of the properties taken from AD I also wish to save to the database in order to execute queries with that property/field as a filter.

I've done as you said, I used a (private) empty setter, but I would have preferred to avoid that. If there is no way I can put this logic in the data access layer, no harm is done. This works.

Thanks.

// Peter


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 2:19 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You said you tried the IInterceptor. What was your problem there ? You should be able to change the value there.

But in my opinion that add's unnecessary complexity to your app, anyway.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 6:17 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I stumbled over IPropertyAccessor while searching the documentation for something else. Seems that you can implement your own access strategy. Maybe you can suppress the "select" there.

Code:
<property name="..." ... access="MyAccessor" />

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 2:18 pm 
Newbie

Joined: Sun Jun 10, 2007 5:32 pm
Posts: 8
Location: Gothenburg
Hi!

It would work with IInterceptor, but with my current design I would have to access the AD twice. I will have a look at IPropertyAccessor or maybe I will have to rethink my design and use IInterceptor only to get data from AD.

Thank you very much for your help and time. It's very much appreciated.

BR // Peter


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.