Skip to content

Commit

Permalink
Added unit test case
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaypaul-ibm committed Jan 22, 2025
1 parent d9f2e7b commit 1bc81ef
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.persistence.testing.models.jpa.advanced.compositepk.CompositePKTableCreator;
import org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Cubicle;
import org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Scientist;
import org.eclipse.persistence.testing.models.jpa.advanced.compositepk.ScientistPK;
import org.junit.Assert;

import java.util.Arrays;
Expand Down Expand Up @@ -121,4 +122,32 @@ public void complexCountOnJoinedCompositePK() {
}
}

public void testCompositePrimaryKey() {
EntityManager em = createEntityManager();
try {
beginTransaction(em);
Scientist scientist = new Scientist();
scientist.setFirstName("John");
scientist.setLastName("Doe");
Cubicle cubicle = new Cubicle();
cubicle.setCode("G");
cubicle.setScientist(scientist);
scientist.setCubicle(cubicle);
em.persist(cubicle);
em.persist(scientist);
em.flush();
List<ScientistPK> keys = getEntityManagerFactory().callInTransaction(entityManager ->
entityManager.createQuery(
"SELECT ID(THIS) FROM Scientist WHERE firstName = :firstName ORDER BY idNumber",
ScientistPK.class
)
.setParameter("firstName", "John")
.getResultList());
assertTrue("The result size should be greater than 0", !keys.isEmpty());
} finally {
rollbackTransaction(em);
}
}


}

0 comments on commit 1bc81ef

Please sign in to comment.