-->
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.  [ 9 posts ] 
Author Message
 Post subject: Criteria eager fetching of collection with alias
PostPosted: Thu Mar 04, 2010 2:58 am 
Newbie

Joined: Wed Feb 07, 2007 8:26 pm
Posts: 17
Dears,

I have a 1:n relation between tables A and B, and I added a restriction to B and want to fetch A and B it eagerly, the question would be what happens when I want to navigate from A to B.

Should you only see the data in B that matches the restriction, or should you see all Bs that are related to A?

Thanks alot


Top
 Profile  
 
 Post subject: Re: Criteria eager fetching of collection with alias
PostPosted: Thu Mar 04, 2010 3:05 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
If you defined the restriction on the relation,
then by navigating from A you should just see the B's which fits the restriction.

If you defined the restriction on the entity B,
then by navigating from A you should see all associated B's.

That's I believe the things are working, but 'The proof of the pudding is in the eating.'


Top
 Profile  
 
 Post subject: Re: Criteria eager fetching of collection with alias
PostPosted: Thu Mar 04, 2010 4:21 am 
Newbie

Joined: Wed Feb 07, 2007 8:26 pm
Posts: 17
Dear Expert,

Thank you for your prompt reply.

Could you please give me an example on "defined the restriction on the relation" because I already defining the restriction on the entity B and I get all the associated B's Which I don't rally want to.


Thanks again


Top
 Profile  
 
 Post subject: Re: Criteria eager fetching of collection with alias
PostPosted: Thu Mar 04, 2010 4:33 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Code:
@Entity
public class A {
    @OneToMany
    @Where(clause="deleted = false")
    private List<B> assB;
}


Top
 Profile  
 
 Post subject: Re: Criteria eager fetching of collection with alias
PostPosted: Thu Mar 04, 2010 4:37 am 
Newbie

Joined: Wed Feb 07, 2007 8:26 pm
Posts: 17
Is it possible to do that in the query not in the mapping?


Top
 Profile  
 
 Post subject: Re: Criteria eager fetching of collection with alias
PostPosted: Thu Mar 04, 2010 4:45 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
Is it possible to do that in the query not in the mapping?


Now I'm confused.
You previously stated that you want to have the restriction feature when you navigate from A to B,
thus is calling a.assB().

Quote:
do that in the query


What do you mean with 'do that in the query' ?
Do you intend to do supply a user-query (HQL, Criteria) and with it's result-set initialize the persistent collection which represents the A-B relation ?


Top
 Profile  
 
 Post subject: Re: Criteria eager fetching of collection with alias
PostPosted: Thu Mar 04, 2010 4:56 am 
Newbie

Joined: Wed Feb 07, 2007 8:26 pm
Posts: 17
Yes, that is what I am trying to do.
I just want to get B that matches the restriction in the user-query when I navigate from A to B "not all associated B's"

Thank you a lot your support.


Top
 Profile  
 
 Post subject: Re: Criteria eager fetching of collection with alias
PostPosted: Thu Mar 04, 2010 6:20 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
supply a user-query (HQL, Criteria) and with it's result-set initialize a persistent collection


I don't know if this is actually feasible, I fear not.


Top
 Profile  
 
 Post subject: Re: Criteria eager fetching of collection with alias
PostPosted: Thu Mar 04, 2010 7:52 am 
Newbie

Joined: Wed Feb 07, 2007 8:26 pm
Posts: 17
Thanks a lot for your help :)


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