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.  [ 4 posts ] 
Author Message
 Post subject: Persist only certain properties of an object
PostPosted: Mon Dec 11, 2006 3:05 pm 
Beginner
Beginner

Joined: Mon Oct 02, 2006 6:46 pm
Posts: 32
Hibernate version: NHibernate1.2.0Beta

Name and version of the database you are using: SQL Server 2000

The generated SQL (show_sql=true): n/a

Is there any way to tell nHibernate not to persist specific properties of an object in certain cases?

I have an object that I want to be able to persist all fields on myself, but I also expose this object to the outside world. I don't want to persist all properties of the object when it is coming in from the outside.

Is this possible without making an entirely new object?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 12, 2006 5:17 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
You can do it in .Net 2.0 by using properties - when you create the properties you can specify an internal protected setter and a public getter.

This doesn't change the persistence mechanism, just the access to changing the values in the persisted object.

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 12, 2006 5:48 am 
Regular
Regular

Joined: Tue Aug 08, 2006 4:28 am
Posts: 96
Location: Hong Kong
Symon,

I guess you would try implementing a custom IInterceptor class. You tell NHibernate session object which properties are dirty in FindDirty(). In other word, you tell NHibernate session that the properties you don't want to persist to be "clean".

It should work but I can't tell if it is a good design.

Canton


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 12, 2006 1:53 pm 
Beginner
Beginner

Joined: Mon Oct 02, 2006 6:46 pm
Posts: 32
thanks for the ideas


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