-->
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.  [ 7 posts ] 
Author Message
 Post subject: More on collections intialization :-(
PostPosted: Thu Jul 21, 2005 7:42 pm 
Newbie

Joined: Thu Jul 21, 2005 3:02 am
Posts: 11
Been searching for several hours I even posted a quest. earlier on this forum - but with no luck - I got an answer but I did not get it to work.

So

My problem seems quite normal.
ObjA has two collections
ObjA.CollectionB and ObjA.CollectionC. Both these collections are quite huge and I want to restrict the items in both collection to be items where items.Year=thisYear-1.

How do I initialize ObjA in such a way that CollectionB and CollectionC ONLY contain items with item.Year=thisYear-1.

My problem is that I cannot have the session open for more than a few secs. So I have to pass ObjA on to a business method (fully initialized with the restrictions on the collections).

I have fiddled around with several queries but can't grasp it.

Is this scenario supported in Hibernate???? or are there other ways to achieve the same??

please help!!

Regards Morten


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 8:11 pm 
Senior
Senior

Joined: Tue Jun 21, 2005 10:18 am
Posts: 135
Location: South Carolina, USA
Just an idea, but you could define an entity representing your Items class that uses the 'where' attribute and map to this entity:

Code:
<class name="Item"
         table="ITEMS"
         where="year = YEAR(CURRENT DATE) - 1"
         entity-name="LastYearItem">
...
</class>


Not sure this would work, but at least it's an idea...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 8:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
collection-level where="..." is also a possibility


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 12:58 am 
Newbie

Joined: Thu Jul 21, 2005 3:02 am
Posts: 11
And how do I change the where clause at runtime??
Year is dependent of what the user wants??

Regards Morten


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 1:58 am 
Senior
Senior

Joined: Tue Jun 21, 2005 10:18 am
Posts: 135
Location: South Carolina, USA
str_mov wrote:
And how do I change the where clause at runtime??
Year is dependent of what the user wants??

Regards Morten


This is sounding more like a query, then.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 5:32 am 
Newbie

Joined: Thu Jul 21, 2005 3:02 am
Posts: 11
Can you show me such a query - because no matter what I try it dosent work.

I CAN get collectionB initialized correctly but CollectionC ALWAYS contains everything.

I do something like.

ObjAInst = _session.CreateQuery("from ObjA oa left join fetch oa.CollectionB cb where oa.Id=34 and cb.Id in (25,26) ").List()[0];

This produces the expected result. Now I want to attach CollectionC to ObjA

_session.CreateQuery("from ObjA oa left join fetch oa.CollectionC cc where cc.Id in (200,201) and oa=:object").SetEntity("object", ObjAInst ).List();


After this call ObjA.CollectionC contains ALL elements - What shall I do and NOT only the ones with Id in (200,201)

I'm gettting a little desperate here - spent days on this issue.....

Regards Morten[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 10:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Use a Hibernate3 Filter.


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