Search in sources :

Example 1 with NonUniqueDiscoveredSqlAliasException

use of org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException in project hibernate-orm by hibernate.

the class SQLTest method test_sql_hibernate_multi_entity_query_example.

@Test
public void test_sql_hibernate_multi_entity_query_example() {
    try {
        doInJPA(this::entityManagerFactory, entityManager -> {
            Session session = entityManager.unwrap(Session.class);
            List<Object> entities = session.createSQLQuery("SELECT * " + "FROM Person pr, Partner pt " + "WHERE pr.name = pt.name").list();
            assertEquals(2, entities.size());
        });
        fail("Should throw NonUniqueDiscoveredSqlAliasException!");
    } catch (NonUniqueDiscoveredSqlAliasException e) {
    // expected
    } catch (PersistenceException e) {
        assertTyping(NonUniqueDiscoveredSqlAliasException.class, e.getCause());
    }
}
Also used : PersistenceException(javax.persistence.PersistenceException) NonUniqueDiscoveredSqlAliasException(org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

PersistenceException (javax.persistence.PersistenceException)1 Session (org.hibernate.Session)1 NonUniqueDiscoveredSqlAliasException (org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException)1 Test (org.junit.Test)1