Search in sources :

Example 1 with Office

use of org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Office in project eclipselink by eclipse-ee4j.

the class AdvancedCompositePKJunitTest method testJoinColumnSharesPK.

public void testJoinColumnSharesPK() {
    EntityManagerFactory emf = getEntityManagerFactory();
    EntityManager em = createEntityManager();
    beginTransaction(em);
    org.eclipse.persistence.descriptors.ClassDescriptor descriptor = getServerSession().getDescriptor(Office.class);
    try {
        Department department = new Department();
        department.setName("DEPT B");
        department.setRole("ROLE B");
        department.setLocation("LOCATION B");
        em.persist(department);
        Office office = new Office();
        office.setId(1);
        office.setLocation("LOCATION B");
        office.setDepartment(department);
        em.persist(office);
        department.getOffices().add(office);
        em.flush();
        clearCache();
        office = em.find(Office.class, new OfficePK(1, "LOCATION B"));
        department = em.find(Department.class, new DepartmentPK("DEPT B", "ROLE B", "LOCATION B"));
        assertTrue("Office's department not properly persisted", office.getDepartment() != null);
        assertTrue("Department's offices not properly persisted", department.getOffices().size() > 0);
    } catch (Exception e) {
        fail("Exception thrown while inserting an object with a read-only column in a foreign key." + e);
    } finally {
        rollbackTransaction(em);
    }
}
Also used : Office(org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Office) EntityManager(jakarta.persistence.EntityManager) Department(org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Department) EntityManagerFactory(jakarta.persistence.EntityManagerFactory) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) OfficePK(org.eclipse.persistence.testing.models.jpa.advanced.compositepk.OfficePK) DepartmentPK(org.eclipse.persistence.testing.models.jpa.advanced.compositepk.DepartmentPK) PersistenceException(jakarta.persistence.PersistenceException)

Aggregations

EntityManager (jakarta.persistence.EntityManager)1 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)1 PersistenceException (jakarta.persistence.PersistenceException)1 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 Department (org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Department)1 DepartmentPK (org.eclipse.persistence.testing.models.jpa.advanced.compositepk.DepartmentPK)1 Office (org.eclipse.persistence.testing.models.jpa.advanced.compositepk.Office)1 OfficePK (org.eclipse.persistence.testing.models.jpa.advanced.compositepk.OfficePK)1