Open JPA query with One to Many Relation

How to fetch data from a child table by querying on parent table in openjpa which is One-to-Many Relationship.
vkchaitu82Asked:
Who is Participating?
 
kingsobConnect With a Mentor Commented:
here is a query what will select all children for a parent

select p from Parent p join fetch p.children where p.id = :id

you could then display a list of the children in jsf with something like this (assuming the child table had a column called name)

<h:dataTable "#{bean.parent.children}" var="child">
    <h:column>
        <h:outputText value="#{child.name}"/>
    </h:column>
</h:dataTable>

you would also need a getter in your bean for the public Parent getParent();


if you were to post your two entity's for the parent and child, i could be more specific to your needs


Derek
0
All Courses

From novice to tech pro — start learning today.