Search in sources :

Example 1 with ExpectedException

use of org.hibernate.testing.orm.junit.ExpectedException in project hibernate-orm by hibernate.

the class AbstractPathImplTest method testGetNonExistingAttributeViaName.

@ExpectedException(value = IllegalArgumentException.class)
@Test
public void testGetNonExistingAttributeViaName() {
    EntityManager em = getOrCreateEntityManager();
    try {
        CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
        CriteriaQuery<Order> criteria = criteriaBuilder.createQuery(Order.class);
        Root<Order> orderRoot = criteria.from(Order.class);
        orderRoot.get("nonExistingAttribute");
    } finally {
        em.close();
    }
}
Also used : CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) Order(org.hibernate.orm.test.jpa.metamodel.Order) EntityManager(jakarta.persistence.EntityManager) AbstractMetamodelSpecificTest(org.hibernate.orm.test.jpa.metamodel.AbstractMetamodelSpecificTest) Test(org.junit.jupiter.api.Test) ExpectedException(org.hibernate.testing.orm.junit.ExpectedException)

Aggregations

EntityManager (jakarta.persistence.EntityManager)1 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)1 AbstractMetamodelSpecificTest (org.hibernate.orm.test.jpa.metamodel.AbstractMetamodelSpecificTest)1 Order (org.hibernate.orm.test.jpa.metamodel.Order)1 ExpectedException (org.hibernate.testing.orm.junit.ExpectedException)1 Test (org.junit.jupiter.api.Test)1