Search in sources :

Example 1 with MS_MS_Entity_Root

use of org.eclipse.persistence.testing.models.jpa.metamodel.MS_MS_Entity_Root in project eclipselink by eclipse-ee4j.

the class MetamodelMetamodelTest method testIdentifiableType_getIdClassAttributesAcrossMappedSuperclassChain_Method.

public void testIdentifiableType_getIdClassAttributesAcrossMappedSuperclassChain_Method() {
    EntityManager em = null;
    boolean expectedIAExceptionThrown = false;
    try {
        em = privateTestSetup();
        assertNotNull(em);
        Metamodel metamodel = em.getMetamodel();
        assertNotNull(metamodel);
        // Actual Test Case
        /**
         *   Return the attributes corresponding to the id class of the
         *   identifiable type.
         *   @return id attributes
         *   @throws IllegalArgumentException if the identifiable type
         *           does not have an id class
         */
        // java.util.Set<SingularAttribute<? super X, ?>> getIdClassAttributes();
        // @IdClass - test normal path
        expectedIAExceptionThrown = false;
        boolean hasSingleIdAttribute = true;
        // 0 id attributes here
        Set<SingularAttribute<? super MS_MS_Entity_Leaf, ?>> idClassAttributesLeaf = null;
        IdentifiableType<MS_MS_Entity_Leaf> aTypeLeaf = metamodel.entity(MS_MS_Entity_Leaf.class);
        // 1 id attribute here
        Set<SingularAttribute<? super MS_MS_Entity_Center, ?>> idClassAttributesCenter = null;
        MappedSuperclassType<MS_MS_Entity_Center> aTypeCenter = (MappedSuperclassType) metamodel.managedType(MS_MS_Entity_Center.class);
        // 3 id attributes here
        Set<SingularAttribute<? super MS_MS_Entity_Root, ?>> idClassAttributesRoot = null;
        MappedSuperclassType<MS_MS_Entity_Root> aTypeRoot = (MappedSuperclassType) metamodel.managedType(MS_MS_Entity_Root.class);
        hasSingleIdAttribute = aTypeLeaf.hasSingleIdAttribute();
        // We verify that an an @IdClass exists above
        // This tests the IdentifiableType part of the transaction for DI 78
        assertFalse(hasSingleIdAttribute);
        hasSingleIdAttribute = aTypeCenter.hasSingleIdAttribute();
        // We verify that an one part of an @IdClass exists
        // This tests the IdentifiableType part of the transaction for DI 78
        assertTrue(hasSingleIdAttribute);
        hasSingleIdAttribute = aTypeRoot.hasSingleIdAttribute();
        // We verify that an @IdClass exists - no single @Id or @EmbeddedId exists
        // This tests the IdentifiableType part of the transaction for DI 78
        assertFalse(hasSingleIdAttribute);
        // idClassAttributesLeaf = aTypeLeaf.getIdClassAttributes(); // expected IAE - leave commented
        idClassAttributesCenter = aTypeCenter.getIdClassAttributes();
        assertNotNull(idClassAttributesCenter);
        assertEquals(1, idClassAttributesCenter.size());
        // The following call is not valid because the IdClass attribute is defined one level below
        try {
            idClassAttributesRoot = aTypeRoot.getIdClassAttributes();
        } catch (IllegalArgumentException iae) {
            expectedIAExceptionThrown = true;
        }
        assertTrue(expectedIAExceptionThrown);
        expectedIAExceptionThrown = false;
    } catch (IllegalArgumentException iae) {
        iae.printStackTrace();
        expectedIAExceptionThrown = true;
    } finally {
        cleanup(em);
        assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
    }
}
Also used : MappedSuperclassType(jakarta.persistence.metamodel.MappedSuperclassType) SingularAttribute(jakarta.persistence.metamodel.SingularAttribute) EntityManager(jakarta.persistence.EntityManager) MS_MS_Entity_Leaf(org.eclipse.persistence.testing.models.jpa.metamodel.MS_MS_Entity_Leaf) MS_MS_Entity_Center(org.eclipse.persistence.testing.models.jpa.metamodel.MS_MS_Entity_Center) MS_MS_Entity_Root(org.eclipse.persistence.testing.models.jpa.metamodel.MS_MS_Entity_Root) Metamodel(jakarta.persistence.metamodel.Metamodel)

Aggregations

EntityManager (jakarta.persistence.EntityManager)1 MappedSuperclassType (jakarta.persistence.metamodel.MappedSuperclassType)1 Metamodel (jakarta.persistence.metamodel.Metamodel)1 SingularAttribute (jakarta.persistence.metamodel.SingularAttribute)1 MS_MS_Entity_Center (org.eclipse.persistence.testing.models.jpa.metamodel.MS_MS_Entity_Center)1 MS_MS_Entity_Leaf (org.eclipse.persistence.testing.models.jpa.metamodel.MS_MS_Entity_Leaf)1 MS_MS_Entity_Root (org.eclipse.persistence.testing.models.jpa.metamodel.MS_MS_Entity_Root)1