-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to query with HQL on annotated list getters?
PostPosted: Thu Feb 05, 2009 6:37 pm 
Newbie

Joined: Thu Feb 05, 2009 6:34 pm
Posts: 5
I have a Hibernate entity, with a getter that is mapped as a @OneToMany:

Code:
@Entity
class Parent extends BaseParent {

    @OneToMany(cascade = {CascadeType.ALL}, mappedBy = "parent")
    public List<Child> getChildren() {
        return super.children;
    }

    public void setChildren(List<Child> list) {
        super.children = list;
    }
}


When I try to execute some HQL like:

Code:
select p
from Parent p
left join p.children c
where c.name='foobar'


I get the following exception:

Code:
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: children of: ....Parent

If I put the @OneToMany annotation on the protected field, the query works. How can I get this to work such that the annotation can be placed on the getter?


Top
 Profile  
 
 Post subject: Re: How to query with HQL on annotated list getters?
PostPosted: Thu Feb 05, 2009 11:38 pm 
Newbie

Joined: Sun Oct 05, 2008 2:45 pm
Posts: 8
Hi,
Can you please try following queries and check if it gives any error.

1) from Parent (it will load eager)
2) select p from Parent p left join fetch p.children
3)select c from children where c.parent = :parent


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 9:17 am 
Newbie

Joined: Thu Feb 05, 2009 6:34 pm
Posts: 5
Turns out I needed a @AccessType("property") annotation on the Parent class. Thanks for the help!


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