Skip to content

Commit 1bc81ef

Browse files
committed
Added unit test case
1 parent d9f2e7b commit 1bc81ef

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

jpa/eclipselink.jpa.testapps/jpa.test.jpql/src/test/java/org/eclipse/persistence/testing/tests/jpa/jpql/advanced/compositepk/JUnitJPQLComplexAggregateTest.java

+29
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.eclipse.persistence.testing.models.jpa.advanced.compositepk.CompositePKTableCreator;
2525
import org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Cubicle;
2626
import org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Scientist;
27+
import org.eclipse.persistence.testing.models.jpa.advanced.compositepk.ScientistPK;
2728
import org.junit.Assert;
2829

2930
import java.util.Arrays;
@@ -121,4 +122,32 @@ public void complexCountOnJoinedCompositePK() {
121122
}
122123
}
123124

125+
public void testCompositePrimaryKey() {
126+
EntityManager em = createEntityManager();
127+
try {
128+
beginTransaction(em);
129+
Scientist scientist = new Scientist();
130+
scientist.setFirstName("John");
131+
scientist.setLastName("Doe");
132+
Cubicle cubicle = new Cubicle();
133+
cubicle.setCode("G");
134+
cubicle.setScientist(scientist);
135+
scientist.setCubicle(cubicle);
136+
em.persist(cubicle);
137+
em.persist(scientist);
138+
em.flush();
139+
List<ScientistPK> keys = getEntityManagerFactory().callInTransaction(entityManager ->
140+
entityManager.createQuery(
141+
"SELECT ID(THIS) FROM Scientist WHERE firstName = :firstName ORDER BY idNumber",
142+
ScientistPK.class
143+
)
144+
.setParameter("firstName", "John")
145+
.getResultList());
146+
assertTrue("The result size should be greater than 0", !keys.isEmpty());
147+
} finally {
148+
rollbackTransaction(em);
149+
}
150+
}
151+
152+
124153
}

0 commit comments

Comments
 (0)