2012-05-31 2 views
1

하이버 네이트 일대 다 단방향 연결에 문제가 있습니다. 매핑 파일 Parent.hbm.xml하이버 네이트 일대 다 단방향 연결, 부모로부터 자식 선택?

<hibernate-mapping> 
<class name="Parent" table="parent"/> 
<id name="id" column="id_parent"/> 
<set name="children" inverse="false" cascade="all"> 
    <key column="id_parent"/> 
    <one-to-many class="Child"/> 
</set> 

</hibernate-mapping> 

Child.hbm.xml

<hibernate-mapping> 
    <class name="Child" table="parent"/> 
    <id name="id" column="id_child"/> 
    <property = "birthday"/>  
    <property="name"/> 
    </hibernate-mapping> 

class Parent{ 
    int id; 
    set <Child> children; 
} 

class Child{ 
    int id; 
    int name; 
    int birthday; 
} 

는, I는 "= 역을 설정하여 일대 일방향 운전 조합을 사용 그릇된".

이름, 생일 및 부모 ID 정보로 올바른 아동을 선택하는 방법은 무엇입니까?

감사합니다. 감사합니다.

+0

Parent.children은 어떻게 매핑됩니까? –

+0

정확히 무엇을하고 싶습니까? 주어진 부모, 주어진 이름 및 주어진 생일이있는 아이를 찾으십시오. –

+0

예, 정확하게 의미하는 것 – lhuang

답변

3
select child from Parent p inner join p.children child 
where p.id = :parentId and child.name = :name and child.birthday = :birthday 

우수한 Hibernate documentation에서 HQL 읽기.

+0

"c"의 정의는 어디에 있습니까? "p.children child" – lhuang

+0

죄송합니다. 죄송합니다. 오식. 이제 해결되었습니다. –