Reputation: 58
I have a problem with Hibernate one-to-many unidirection association.
class Parent{
int id;
set <Child> children;
}
class Child{
int id;
int name;
int birthday;
}
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>
in the mapping file, I use one-to-many unidirection association by setting inverse="false".
How to select the right child with the his name, birthday and parent ID infos?
best regards Thanks!
Upvotes: 1
Views: 1248
Reputation: 692121
select child from Parent p inner join p.children child
where p.id = :parentId and child.name = :name and child.birthday = :birthday
Read on HQL in the excellent Hibernate documentation.
Upvotes: 3