Search in sources :

Example 1 with UnknownEntityTypeException

use of org.hibernate.UnknownEntityTypeException in project hibernate-orm by hibernate.

the class EntityNonEntityTest method testGetAndFindNonEntityThrowsIllegalArgumentException.

@Test
@TestForIssue(jiraKey = "HHH-9856")
public void testGetAndFindNonEntityThrowsIllegalArgumentException() {
    try {
        sessionFactory().locateEntityPersister(Cellular.class);
    } catch (UnknownEntityTypeException ignore) {
    // expected
    }
    try {
        sessionFactory().locateEntityPersister(Cellular.class.getName());
    } catch (UnknownEntityTypeException ignore) {
    // expected
    }
    Session s = openSession();
    s.beginTransaction();
    try {
        s.get(Cellular.class, 1);
        fail("Expecting a failure");
    } catch (UnknownEntityTypeException ignore) {
    // expected
    } finally {
        s.getTransaction().commit();
        s.close();
    }
    s = openSession();
    s.beginTransaction();
    try {
        s.get(Cellular.class.getName(), 1);
        fail("Expecting a failure");
    } catch (UnknownEntityTypeException ignore) {
    // expected
    } finally {
        s.getTransaction().commit();
        s.close();
    }
}
Also used : UnknownEntityTypeException(org.hibernate.UnknownEntityTypeException) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 2 with UnknownEntityTypeException

use of org.hibernate.UnknownEntityTypeException in project hibernate-orm by hibernate.

the class DomainModelScope method withHierarchy.

default void withHierarchy(String rootTypeName, Consumer<RootClass> action) {
    final PersistentClass entityBinding = getDomainModel().getEntityBinding(rootTypeName);
    if (entityBinding == null) {
        throw new UnknownEntityTypeException(String.format(Locale.ROOT, "Could not resolve `%s` as an entity type", rootTypeName));
    }
    action.accept(entityBinding.getRootClass());
}
Also used : UnknownEntityTypeException(org.hibernate.UnknownEntityTypeException) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 3 with UnknownEntityTypeException

use of org.hibernate.UnknownEntityTypeException in project hibernate-orm by hibernate.

the class EntityNonEntityTest method testGetAndFindNonEntityThrowsIllegalArgumentException.

@Test
@TestForIssue(jiraKey = "HHH-9856")
public void testGetAndFindNonEntityThrowsIllegalArgumentException() {
    try {
        sessionFactory().getMetamodel().locateEntityPersister(Cellular.class);
        sessionFactory().getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(Cellular.class);
    } catch (UnknownEntityTypeException ignore) {
    // expected
    }
    try {
        sessionFactory().getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(Cellular.class.getName());
    } catch (UnknownEntityTypeException ignore) {
    // expected
    }
    Session s = openSession();
    s.beginTransaction();
    try {
        s.get(Cellular.class, 1);
        fail("Expecting a failure");
    } catch (UnknownEntityTypeException ignore) {
    // expected
    } finally {
        s.getTransaction().commit();
        s.close();
    }
    s = openSession();
    s.beginTransaction();
    try {
        s.get(Cellular.class.getName(), 1);
        fail("Expecting a failure");
    } catch (UnknownEntityTypeException ignore) {
    // expected
    } finally {
        s.getTransaction().commit();
        s.close();
    }
}
Also used : UnknownEntityTypeException(org.hibernate.UnknownEntityTypeException) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

UnknownEntityTypeException (org.hibernate.UnknownEntityTypeException)3 Session (org.hibernate.Session)2 TestForIssue (org.hibernate.testing.TestForIssue)2 Test (org.junit.Test)2 PersistentClass (org.hibernate.mapping.PersistentClass)1