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.  [ 2 posts ] 
Author Message
 Post subject: Collection Question
PostPosted: Thu Mar 01, 2007 10:16 am 
Regular
Regular

Joined: Fri May 05, 2006 11:54 am
Posts: 51
Hi,

I have a query concerning unsurprisingly NHibernate. The problem is ths.

I have a class named Recipe. A Recipe has a collection of attribues. In my mapping file this is defined as:

Code:
<bag name="Attributes" inverse="false" lazy="true" generic="true" cascade="save-update">
<key column="RecipeUid"/>
   <many-to-many class="domain.Attribute, core" column="AttributeId"/>
</bag>


My question is what is the best way of persisting this collection without having to load the many to many class from the database for each attribute?

If I do the following:

Code:
domain.Attribute att = new domain.Attribute(1);
recipe.Attributes.Add(att);


NHibernate thinks that att is a new object and tries to save this instance to the database.

The only way I can get this to work is to load the Attribute object from the database and then add it to the Recipe's attribute collecction and then save it.

This seems inefficient.

Can anyone tell me a better way?

Cheers

Paul


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 02, 2007 6:15 am 
Regular
Regular

Joined: Fri May 05, 2006 11:54 am
Posts: 51
I have quite a complex structure with composite-elements that contain many-to-one classes etc.

It is an ASP.NET app. so my only way would be to cache the lookups or something like that. I cannot use second level caching because it is a web farm and the MemCache is

Is there no way to tell NHibernate that the object is not to be saved to the db. The only way seems to pull it from the Session via loading it from the db.

I will have to do a lot of loading in order to persist it.

How do people generally approach this situation.


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