-->
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: Reading one item from a collection using a formula
PostPosted: Tue Jun 26, 2007 8:52 pm 
Beginner
Beginner

Joined: Sun Apr 09, 2006 9:07 pm
Posts: 24
Hibernate version: 1.2.0 GA

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

Mapping documents:

<class name="UserProfile" table="user_profile">
...
<bag name="CurrentProducts" table="Products" inverse="true" cascade="all-delete-orphan" order-by="expiryDate, productDefinitionId ASC">
<key column="memberId" />
<one-to-many class="common.Product, common" />
</bag>
</class>


I have a child collection of Products. Suppose I don't usually need to load all the products, but I often need to load a particular one (the one that expires next). Is there a way to do this using NHibernate with a formula property? I tried to do it using the following mapping:

<property name="TestProduct" type="au.com.venturelogic.linkme.common.Product, common"
formula="SELECT TOP 1 * FROM Product p WHERE p.memberId = id ORDER BY p.expiryDate" />

However, NHibernate doesn't seem to accept a mapped class as a property type.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 12:49 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You could try <many-to-one formula...>, or use a collection filter (ISession.CreateFilter(myObject.myCollection, query text)).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 11:22 pm 
Beginner
Beginner

Joined: Sun Apr 09, 2006 9:07 pm
Posts: 24
"many-to-one forumula" doesn't seem to be supported. NHibernate throws an exception: System.Xml.Schema.XmlSchemaException: The 'formula' attribute is not declared.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 2:17 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Ok so it wasn't ported yet. This leaves you with the collection filter, I guess.


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.