-->
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: Mapping help
PostPosted: Wed Feb 08, 2006 12:18 pm 
Newbie

Joined: Tue Jul 26, 2005 4:32 pm
Posts: 8
Hibernate version: 2

I have a mapped object, let's call it product:
------------------------------
| id | .... other colums |
--------------------------------
| 1 | ...
| 2 | ...
and a table representing monthly data related to this product.

------------------------------------
| product_id | month | data
-----------------------------------
| 1 | 20060201 | 50
| 1 | 20060101 | 60
| 1 | 20051201 | 40
etc.

I need to map the data object in such a way that when the
product is loaded, data for the current month and 11 previous months
is loaded with it).

Any ideas to do this in the most efficient way possible?
Thanks.
-Jeff


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 2:24 pm 
Newbie

Joined: Wed Jan 28, 2004 5:18 am
Posts: 11
I would create a filtered collection with the condition you want as a SQL filter (see "where" attribute for collections), and map it with lazy="false" (and perhaps fetch="select" if necessary)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 12:07 pm 
Newbie

Joined: Tue Jul 26, 2005 4:32 pm
Posts: 8
Ok, let's say I map this data object as a map:
<map
name="datamap"
table="datatable"
>
<key column="PRODUCT_ID">
</key>

<element
column="MONTH"
type="Date"
not-null="false"
unique="false"
/>
<element
column="DATA"
type="double"
not-null="false"
unique="false"
/>

</map>

And I use criteria api to retrieve my products. Where and how would
I put a filter?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 3:59 am 
Newbie

Joined: Wed Jan 28, 2004 5:18 am
Posts: 11
You should put 'where="SQL where condition"' as attribute in <map> element.
As for the exact SQL where condition, I am no SQL expert, but it should not be too hard to put the condition you need - maybe define your own function in the database, depending on the database you have.


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.