Skip to content

Commit

Permalink
HHH-11416 : Fix test to run on pre-5.2 branches
Browse files Browse the repository at this point in the history
  • Loading branch information
gbadner committed May 10, 2017
1 parent e3c8086 commit b66014b
Showing 1 changed file with 13 additions and 5 deletions.
Expand Up @@ -9,6 +9,7 @@
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
Expand All @@ -21,7 +22,6 @@
import org.junit.Test;

import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.transaction.TransactionUtil;

import static org.junit.Assert.assertEquals;

Expand All @@ -38,7 +38,9 @@ protected Class<?>[] getAnnotatedClasses() {
@Test
@Priority(10)
public void initData() {
TransactionUtil.doInJPA( this::entityManagerFactory, entityManager -> {
EntityManager entityManager = getOrCreateEntityManager();
entityManager.getTransaction().begin();
{
final EntityC c1 = new EntityC();
c1.setId( 1 );
c1.setName( "c1" );
Expand All @@ -52,7 +54,9 @@ public void initData() {
a1.setRelationToC( c1 );
a1.setPropA( "propC" );
entityManager.persist( a1 );
} );
}
entityManager.getTransaction().commit();
entityManager.close();
}

@Test
Expand Down Expand Up @@ -95,10 +99,14 @@ public void testAuditQueryWithJoinedInheritanceUnrelatedPropertyJoin() {
@Test
public void testHibernateUnrelatedPropertyQuery() {
final String queryString = "FROM EntityA a Inner Join EntityC c ON a.propA = c.propC Where c.propB = :propB";
TransactionUtil.doInJPA( this::entityManagerFactory, entityManager -> {
EntityManager entityManager = getOrCreateEntityManager();
entityManager.getTransaction().begin();
{
List results = entityManager.createQuery( queryString ).setParameter( "propB", "propB" ).getResultList();
assertEquals( 1, results.size() );
} );
}
entityManager.getTransaction().commit();
entityManager.close();
}

@Entity(name = "EntityA")
Expand Down

0 comments on commit b66014b

Please sign in to comment.