Search in sources :

Example 1 with MemberDetails

use of org.datanucleus.samples.annotations.one_many.unidir_2.MemberDetails in project tests by datanucleus.

the class JPQLQueryTest method testJoinMultipleFields.

/**
 * Test for join across multiple fields in single join.
 */
public void testJoinMultipleFields() {
    try {
        EntityManager em = getEM();
        EntityTransaction tx = em.getTransaction();
        try {
            tx.begin();
            UserGroup grp = new UserGroup(101, "JPOX Users");
            GroupMember member1 = new GroupMember(201, "Joe User");
            MemberDetails memDets = new MemberDetails(301, "Joe", "User");
            member1.setDetails(memDets);
            grp.getMembers().add(member1);
            em.persist(grp);
            em.flush();
            List result = em.createQuery("SELECT G FROM " + UserGroup.class.getName() + " G INNER JOIN G.members.details D").getResultList();
            assertEquals(1, result.size());
            tx.rollback();
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            em.close();
        }
    } finally {
        clean(UserGroup.class);
        clean(GroupMember.class);
        clean(MemberDetails.class);
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) ExpertGroupMember(org.datanucleus.samples.annotations.one_many.unidir_2.ExpertGroupMember) GroupMember(org.datanucleus.samples.annotations.one_many.unidir_2.GroupMember) EntityManager(javax.persistence.EntityManager) List(java.util.List) ArrayList(java.util.ArrayList) MemberDetails(org.datanucleus.samples.annotations.one_many.unidir_2.MemberDetails) ModeratedUserGroup(org.datanucleus.samples.annotations.one_many.unidir_2.ModeratedUserGroup) UserGroup(org.datanucleus.samples.annotations.one_many.unidir_2.UserGroup)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 EntityManager (javax.persistence.EntityManager)1 EntityTransaction (javax.persistence.EntityTransaction)1 ExpertGroupMember (org.datanucleus.samples.annotations.one_many.unidir_2.ExpertGroupMember)1 GroupMember (org.datanucleus.samples.annotations.one_many.unidir_2.GroupMember)1 MemberDetails (org.datanucleus.samples.annotations.one_many.unidir_2.MemberDetails)1 ModeratedUserGroup (org.datanucleus.samples.annotations.one_many.unidir_2.ModeratedUserGroup)1 UserGroup (org.datanucleus.samples.annotations.one_many.unidir_2.UserGroup)1