HHH-11559 - Fix tests catching exceptions without re-throwing them
This commit is contained in:
parent
17b8d2e294
commit
1ced091409
|
@ -9,8 +9,8 @@ package org.hibernate.jpa.test.criteria;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.Parameter;
|
import javax.persistence.Parameter;
|
||||||
import javax.persistence.TypedQuery;
|
import javax.persistence.TypedQuery;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Expression;
|
|
||||||
import javax.persistence.criteria.ParameterExpression;
|
import javax.persistence.criteria.ParameterExpression;
|
||||||
import javax.persistence.criteria.Path;
|
import javax.persistence.criteria.Path;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
|
@ -22,6 +22,7 @@ import org.junit.Test;
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.hibernate.testing.transaction.TransactionUtil;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -122,32 +123,20 @@ public class ParameterTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-10870")
|
@TestForIssue(jiraKey = "HHH-10870")
|
||||||
public void testParameterInParameterList2() {
|
public void testParameterInParameterList2() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
TransactionUtil.doInJPA( this::entityManagerFactory, em -> {
|
||||||
try {
|
final CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
|
||||||
em.getTransaction().begin();
|
final CriteriaQuery<MultiTypedBasicAttributesEntity> criteria = criteriaBuilder
|
||||||
final CriteriaQuery<MultiTypedBasicAttributesEntity> query = em.getCriteriaBuilder()
|
|
||||||
.createQuery( MultiTypedBasicAttributesEntity.class );
|
.createQuery( MultiTypedBasicAttributesEntity.class );
|
||||||
|
|
||||||
final Root<MultiTypedBasicAttributesEntity> root = query.from( MultiTypedBasicAttributesEntity.class );
|
final ParameterExpression<Iterable> parameter = criteriaBuilder.parameter( Iterable.class );
|
||||||
root.get( "id" );
|
|
||||||
final ParameterExpression<Iterable> parameter = em.getCriteriaBuilder().parameter( Iterable.class );
|
|
||||||
root.in( new Expression[] {parameter} );
|
|
||||||
query.select( root );
|
|
||||||
|
|
||||||
final TypedQuery<MultiTypedBasicAttributesEntity> query1 = em.createQuery( query );
|
final Root<MultiTypedBasicAttributesEntity> root = criteria.from( MultiTypedBasicAttributesEntity.class );
|
||||||
|
criteria.select( root ).where( root.get( "id" ).in( parameter ) );
|
||||||
|
|
||||||
|
final TypedQuery<MultiTypedBasicAttributesEntity> query1 = em.createQuery( criteria );
|
||||||
query1.setParameter( parameter, Arrays.asList( 1L, 2L, 3L ) );
|
query1.setParameter( parameter, Arrays.asList( 1L, 2L, 3L ) );
|
||||||
query1.getResultList();
|
query1.getResultList();
|
||||||
|
} );
|
||||||
em.getTransaction().commit();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
if ( em.getTransaction().isActive() ) {
|
|
||||||
em.getTransaction().rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
em.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -86,12 +86,12 @@ public class EmbeddableIntegratorTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
Investor inv = (Investor) sess.get( Investor.class, 2L );
|
Investor inv = (Investor) sess.get( Investor.class, 2L );
|
||||||
assertEquals( new BigDecimal( "100" ), inv.getInvestments().get( 0 ).getAmount().getAmount() );
|
assertEquals( new BigDecimal( "100" ), inv.getInvestments().get( 0 ).getAmount().getAmount() );
|
||||||
|
|
||||||
sess.close();
|
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
sess.getTransaction().rollback();
|
sess.getTransaction().rollback();
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
sess.close();
|
||||||
sf.close();
|
sf.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl;
|
||||||
import org.hibernate.testing.FailureExpected;
|
import org.hibernate.testing.FailureExpected;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||||
|
import org.hibernate.testing.transaction.TransactionUtil;
|
||||||
import org.hibernate.test.annotations.embedded.FloatLeg.RateIndex;
|
import org.hibernate.test.annotations.embedded.FloatLeg.RateIndex;
|
||||||
import org.hibernate.test.annotations.embedded.Leg.Frequency;
|
import org.hibernate.test.annotations.embedded.Leg.Frequency;
|
||||||
import org.hibernate.test.util.SchemaUtil;
|
import org.hibernate.test.util.SchemaUtil;
|
||||||
|
@ -40,9 +41,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
public class EmbeddedTest extends BaseNonConfigCoreFunctionalTestCase {
|
public class EmbeddedTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testSimple() throws Exception {
|
public void testSimple() throws Exception {
|
||||||
Session s;
|
Person person = new Person();
|
||||||
Transaction tx;
|
|
||||||
Person p = new Person();
|
|
||||||
Address a = new Address();
|
Address a = new Address();
|
||||||
Country c = new Country();
|
Country c = new Country();
|
||||||
Country bornCountry = new Country();
|
Country bornCountry = new Country();
|
||||||
|
@ -54,28 +53,16 @@ public class EmbeddedTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
a.address1 = "colorado street";
|
a.address1 = "colorado street";
|
||||||
a.city = "Springfield";
|
a.city = "Springfield";
|
||||||
a.country = c;
|
a.country = c;
|
||||||
p.address = a;
|
person.address = a;
|
||||||
p.bornIn = bornCountry;
|
person.bornIn = bornCountry;
|
||||||
p.name = "Homer";
|
person.name = "Homer";
|
||||||
s = openSession();
|
|
||||||
tx = s.beginTransaction();
|
|
||||||
try {
|
|
||||||
s.persist( p );
|
|
||||||
tx.commit();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
if ( tx != null && tx.isActive() ) {
|
|
||||||
tx.rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
s = openSession();
|
TransactionUtil.doInHibernate( this::sessionFactory, session ->{
|
||||||
tx = s.beginTransaction();
|
session.persist( person );
|
||||||
try {
|
} );
|
||||||
p = (Person) s.get( Person.class, p.id );
|
|
||||||
|
TransactionUtil.doInHibernate( this::sessionFactory, session ->{
|
||||||
|
Person p = session.get( Person.class, person.id );
|
||||||
assertNotNull( p );
|
assertNotNull( p );
|
||||||
assertNotNull( p.address );
|
assertNotNull( p.address );
|
||||||
assertEquals( "Springfield", p.address.city );
|
assertEquals( "Springfield", p.address.city );
|
||||||
|
@ -83,24 +70,13 @@ public class EmbeddedTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
assertEquals( "DM", p.address.country.getIso2() );
|
assertEquals( "DM", p.address.country.getIso2() );
|
||||||
assertNotNull( p.bornIn );
|
assertNotNull( p.bornIn );
|
||||||
assertEquals( "US", p.bornIn.getIso2() );
|
assertEquals( "US", p.bornIn.getIso2() );
|
||||||
tx.commit();
|
} );
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
if ( tx != null && tx.isActive() ) {
|
|
||||||
tx.rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-8172")
|
@TestForIssue(jiraKey = "HHH-8172")
|
||||||
public void testQueryWithEmbeddedIsNull() throws Exception {
|
public void testQueryWithEmbeddedIsNull() throws Exception {
|
||||||
Session s;
|
Person person = new Person();
|
||||||
Transaction tx;
|
|
||||||
Person p = new Person();
|
|
||||||
Address a = new Address();
|
Address a = new Address();
|
||||||
Country c = new Country();
|
Country c = new Country();
|
||||||
Country bornCountry = new Country();
|
Country bornCountry = new Country();
|
||||||
|
@ -112,44 +88,22 @@ public class EmbeddedTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
a.address1 = "colorado street";
|
a.address1 = "colorado street";
|
||||||
a.city = "Springfield";
|
a.city = "Springfield";
|
||||||
a.country = c;
|
a.country = c;
|
||||||
p.address = a;
|
person.address = a;
|
||||||
p.bornIn = bornCountry;
|
person.bornIn = bornCountry;
|
||||||
p.name = "Homer";
|
person.name = "Homer";
|
||||||
s = openSession();
|
TransactionUtil.doInHibernate( this::sessionFactory, session -> {
|
||||||
tx = s.beginTransaction();
|
session.persist( person );
|
||||||
try {
|
} );
|
||||||
s.persist( p );
|
|
||||||
tx.commit();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
if ( tx != null && tx.isActive() ) {
|
|
||||||
tx.rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
s = openSession();
|
TransactionUtil.doInHibernate( this::sessionFactory, session -> {
|
||||||
tx = s.beginTransaction();
|
Person p = (Person) session.createQuery( "from Person p where p.bornIn is null" ).uniqueResult();
|
||||||
try {
|
|
||||||
p = (Person) s.createQuery( "from Person p where p.bornIn is null" ).uniqueResult();
|
|
||||||
assertNotNull( p );
|
assertNotNull( p );
|
||||||
assertNotNull( p.address );
|
assertNotNull( p.address );
|
||||||
assertEquals( "Springfield", p.address.city );
|
assertEquals( "Springfield", p.address.city );
|
||||||
assertNotNull( p.address.country );
|
assertNotNull( p.address.country );
|
||||||
assertEquals( "DM", p.address.country.getIso2() );
|
assertEquals( "DM", p.address.country.getIso2() );
|
||||||
assertNull( p.bornIn );
|
assertNull( p.bornIn );
|
||||||
tx.commit();
|
} );
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
if ( tx != null && tx.isActive() ) {
|
|
||||||
tx.rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -158,7 +112,7 @@ public class EmbeddedTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
public void testQueryWithEmbeddedParameterAllNull() throws Exception {
|
public void testQueryWithEmbeddedParameterAllNull() throws Exception {
|
||||||
Session s;
|
Session s;
|
||||||
Transaction tx;
|
Transaction tx;
|
||||||
Person p = new Person();
|
Person person = new Person();
|
||||||
Address a = new Address();
|
Address a = new Address();
|
||||||
Country c = new Country();
|
Country c = new Country();
|
||||||
Country bornCountry = new Country();
|
Country bornCountry = new Country();
|
||||||
|
@ -168,29 +122,17 @@ public class EmbeddedTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
a.address1 = "colorado street";
|
a.address1 = "colorado street";
|
||||||
a.city = "Springfield";
|
a.city = "Springfield";
|
||||||
a.country = c;
|
a.country = c;
|
||||||
p.address = a;
|
person.address = a;
|
||||||
p.bornIn = bornCountry;
|
person.bornIn = bornCountry;
|
||||||
p.name = "Homer";
|
person.name = "Homer";
|
||||||
s = openSession();
|
|
||||||
tx = s.beginTransaction();
|
|
||||||
try {
|
|
||||||
s.persist( p );
|
|
||||||
tx.commit();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
if ( tx != null && tx.isActive() ) {
|
|
||||||
tx.rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
s = openSession();
|
TransactionUtil.doInHibernate( this::sessionFactory, session -> {
|
||||||
tx = s.beginTransaction();
|
session.persist( person );
|
||||||
try {
|
} );
|
||||||
p = (Person) s.createQuery( "from Person p where p.bornIn = :b" )
|
|
||||||
.setParameter( "b", p.bornIn )
|
TransactionUtil.doInHibernate( this::sessionFactory, session -> {
|
||||||
|
Person p = (Person) session.createQuery( "from Person p where p.bornIn = :b" )
|
||||||
|
.setParameter( "b", person.bornIn )
|
||||||
.uniqueResult();
|
.uniqueResult();
|
||||||
assertNotNull( p );
|
assertNotNull( p );
|
||||||
assertNotNull( p.address );
|
assertNotNull( p.address );
|
||||||
|
@ -198,25 +140,14 @@ public class EmbeddedTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
assertNotNull( p.address.country );
|
assertNotNull( p.address.country );
|
||||||
assertEquals( "DM", p.address.country.getIso2() );
|
assertEquals( "DM", p.address.country.getIso2() );
|
||||||
assertNull( p.bornIn );
|
assertNull( p.bornIn );
|
||||||
tx.commit();
|
} );
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
if ( tx != null && tx.isActive() ) {
|
|
||||||
tx.rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-8172")
|
@TestForIssue(jiraKey = "HHH-8172")
|
||||||
@FailureExpected(jiraKey = "HHH-8172")
|
@FailureExpected(jiraKey = "HHH-8172")
|
||||||
public void testQueryWithEmbeddedParameterOneNull() throws Exception {
|
public void testQueryWithEmbeddedParameterOneNull() throws Exception {
|
||||||
Session s;
|
Person person = new Person();
|
||||||
Transaction tx;
|
|
||||||
Person p = new Person();
|
|
||||||
Address a = new Address();
|
Address a = new Address();
|
||||||
Country c = new Country();
|
Country c = new Country();
|
||||||
Country bornCountry = new Country();
|
Country bornCountry = new Country();
|
||||||
|
@ -228,29 +159,17 @@ public class EmbeddedTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
a.address1 = "colorado street";
|
a.address1 = "colorado street";
|
||||||
a.city = "Springfield";
|
a.city = "Springfield";
|
||||||
a.country = c;
|
a.country = c;
|
||||||
p.address = a;
|
person.address = a;
|
||||||
p.bornIn = bornCountry;
|
person.bornIn = bornCountry;
|
||||||
p.name = "Homer";
|
person.name = "Homer";
|
||||||
s = openSession();
|
|
||||||
tx = s.beginTransaction();
|
|
||||||
try {
|
|
||||||
s.persist( p );
|
|
||||||
tx.commit();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
if ( tx != null && tx.isActive() ) {
|
|
||||||
tx.rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
s = openSession();
|
TransactionUtil.doInHibernate( this::sessionFactory, session -> {
|
||||||
tx = s.beginTransaction();
|
session.persist( person );
|
||||||
try {
|
} );
|
||||||
p = (Person) s.createQuery( "from Person p where p.bornIn = :b" )
|
|
||||||
.setParameter( "b", p.bornIn )
|
TransactionUtil.doInHibernate( this::sessionFactory, session -> {
|
||||||
|
Person p = (Person) session.createQuery( "from Person p where p.bornIn = :b" )
|
||||||
|
.setParameter( "b", person.bornIn )
|
||||||
.uniqueResult();
|
.uniqueResult();
|
||||||
assertNotNull( p );
|
assertNotNull( p );
|
||||||
assertNotNull( p.address );
|
assertNotNull( p.address );
|
||||||
|
@ -259,24 +178,13 @@ public class EmbeddedTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
assertEquals( "DM", p.address.country.getIso2() );
|
assertEquals( "DM", p.address.country.getIso2() );
|
||||||
assertEquals( "US", p.bornIn.getIso2() );
|
assertEquals( "US", p.bornIn.getIso2() );
|
||||||
assertNull( p.bornIn.getName() );
|
assertNull( p.bornIn.getName() );
|
||||||
tx.commit();
|
} );
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
if ( tx != null && tx.isActive() ) {
|
|
||||||
tx.rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-8172")
|
@TestForIssue(jiraKey = "HHH-8172")
|
||||||
public void testQueryWithEmbeddedWithNullUsingSubAttributes() throws Exception {
|
public void testQueryWithEmbeddedWithNullUsingSubAttributes() throws Exception {
|
||||||
Session s;
|
Person person = new Person();
|
||||||
Transaction tx;
|
|
||||||
Person p = new Person();
|
|
||||||
Address a = new Address();
|
Address a = new Address();
|
||||||
Country c = new Country();
|
Country c = new Country();
|
||||||
Country bornCountry = new Country();
|
Country bornCountry = new Country();
|
||||||
|
@ -288,32 +196,19 @@ public class EmbeddedTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
a.address1 = "colorado street";
|
a.address1 = "colorado street";
|
||||||
a.city = "Springfield";
|
a.city = "Springfield";
|
||||||
a.country = c;
|
a.country = c;
|
||||||
p.address = a;
|
person.address = a;
|
||||||
p.bornIn = bornCountry;
|
person.bornIn = bornCountry;
|
||||||
p.name = "Homer";
|
person.name = "Homer";
|
||||||
s = openSession();
|
TransactionUtil.doInHibernate( this::sessionFactory, session -> {
|
||||||
tx = s.beginTransaction();
|
session.persist( person );
|
||||||
try {
|
} );
|
||||||
s.persist( p );
|
|
||||||
tx.commit();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
if ( tx != null && tx.isActive() ) {
|
|
||||||
tx.rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
s = openSession();
|
TransactionUtil.doInHibernate( this::sessionFactory, session -> {
|
||||||
tx = s.beginTransaction();
|
Person p = (Person) session.createQuery( "from Person p " +
|
||||||
try {
|
"where ( p.bornIn.iso2 is null or p.bornIn.iso2 = :i ) and " +
|
||||||
p = (Person) s.createQuery( "from Person p " +
|
"( p.bornIn.name is null or p.bornIn.name = :n )"
|
||||||
"where ( p.bornIn.iso2 is null or p.bornIn.iso2 = :i ) and " +
|
).setParameter( "i", person.bornIn.getIso2() )
|
||||||
"( p.bornIn.name is null or p.bornIn.name = :n )"
|
.setParameter( "n", person.bornIn.getName() )
|
||||||
).setParameter( "i", p.bornIn.getIso2() )
|
|
||||||
.setParameter( "n", p.bornIn.getName() )
|
|
||||||
.uniqueResult();
|
.uniqueResult();
|
||||||
assertNotNull( p );
|
assertNotNull( p );
|
||||||
assertNotNull( p.address );
|
assertNotNull( p.address );
|
||||||
|
@ -322,16 +217,7 @@ public class EmbeddedTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
assertEquals( "DM", p.address.country.getIso2() );
|
assertEquals( "DM", p.address.country.getIso2() );
|
||||||
assertEquals( "US", p.bornIn.getIso2() );
|
assertEquals( "US", p.bornIn.getIso2() );
|
||||||
assertNull( p.bornIn.getName() );
|
assertNull( p.bornIn.getName() );
|
||||||
tx.commit();
|
} );
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
if ( tx != null && tx.isActive() ) {
|
|
||||||
tx.rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -6,9 +6,11 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.annotations.filter.secondarytable;
|
package org.hibernate.test.annotations.filter.secondarytable;
|
||||||
|
|
||||||
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
import org.hibernate.testing.transaction.TransactionUtil;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -21,35 +23,43 @@ public class SecondaryTableTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void prepareTest() throws Exception {
|
protected void prepareTest() throws Exception {
|
||||||
Session s = openSession();
|
TransactionUtil.doInHibernate( this::sessionFactory, s -> {
|
||||||
s.beginTransaction();
|
insertUser( s, "q@s.com", 21, false, "a1", "b" );
|
||||||
try {
|
insertUser( s, "r@s.com", 22, false, "a2", "b" );
|
||||||
insertUser( "q@s.com", 21, false, "a1", "b" );
|
insertUser( s, "s@s.com", 23, true, "a3", "b" );
|
||||||
insertUser( "r@s.com", 22, false, "a2", "b" );
|
insertUser( s, "t@s.com", 24, false, "a4", "b" );
|
||||||
insertUser( "s@s.com", 23, true, "a3", "b" );
|
} );
|
||||||
insertUser( "t@s.com", 24, false, "a4", "b" );
|
}
|
||||||
session.flush();
|
|
||||||
s.getTransaction().commit();
|
@Test
|
||||||
}catch (Exception e){
|
public void testFilter() {
|
||||||
s.getTransaction().rollback();
|
try (Session session = openSession()) {
|
||||||
|
Assert.assertEquals(
|
||||||
|
Long.valueOf( 4 ),
|
||||||
|
session.createQuery( "select count(u) from User u" ).uniqueResult()
|
||||||
|
);
|
||||||
|
session.enableFilter( "ageFilter" ).setParameter( "age", 24 );
|
||||||
|
Assert.assertEquals(
|
||||||
|
Long.valueOf( 2 ),
|
||||||
|
session.createQuery( "select count(u) from User u" ).uniqueResult()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
private void insertUser(
|
||||||
public void testFilter(){
|
Session session,
|
||||||
Assert.assertEquals(Long.valueOf(4), session.createQuery("select count(u) from User u").uniqueResult());
|
String emailAddress,
|
||||||
session.enableFilter("ageFilter").setParameter("age", 24);
|
int age,
|
||||||
Assert.assertEquals(Long.valueOf(2), session.createQuery("select count(u) from User u").uniqueResult());
|
boolean lockedOut,
|
||||||
}
|
String username,
|
||||||
|
String password) {
|
||||||
private void insertUser(String emailAddress, int age, boolean lockedOut, String username, String password){
|
|
||||||
User user = new User();
|
User user = new User();
|
||||||
user.setEmailAddress(emailAddress);
|
user.setEmailAddress( emailAddress );
|
||||||
user.setAge(age);
|
user.setAge( age );
|
||||||
user.setLockedOut(lockedOut);
|
user.setLockedOut( lockedOut );
|
||||||
user.setUsername(username);
|
user.setUsername( username );
|
||||||
user.setPassword(password);
|
user.setPassword( password );
|
||||||
session.persist(user);
|
session.persist( user );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,23 +41,28 @@ public class EmptyCompositesDirtynessTest extends BaseCoreFunctionalTestCase {
|
||||||
@TestForIssue(jiraKey = "HHH-7610")
|
@TestForIssue(jiraKey = "HHH-7610")
|
||||||
public void testCompositesEmpty() {
|
public void testCompositesEmpty() {
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
s.getTransaction().begin();
|
try {
|
||||||
|
s.getTransaction().begin();
|
||||||
|
|
||||||
ComponentEmptyEmbeddedOwner owner = new ComponentEmptyEmbeddedOwner();
|
ComponentEmptyEmbeddedOwner owner = new ComponentEmptyEmbeddedOwner();
|
||||||
s.persist( owner );
|
s.persist( owner );
|
||||||
|
|
||||||
s.flush();
|
s.flush();
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
|
|
||||||
s.clear();
|
s.clear();
|
||||||
s.getTransaction().begin();
|
s.getTransaction().begin();
|
||||||
owner = (ComponentEmptyEmbeddedOwner) s.get( ComponentEmptyEmbeddedOwner.class, owner.getId() );
|
owner = (ComponentEmptyEmbeddedOwner) s.get( ComponentEmptyEmbeddedOwner.class, owner.getId() );
|
||||||
assertNull( owner.getEmbedded() );
|
assertNull( owner.getEmbedded() );
|
||||||
owner.setEmbedded( new ComponentEmptyEmbedded() );
|
owner.setEmbedded( new ComponentEmptyEmbedded() );
|
||||||
|
|
||||||
// technically, as all properties are null, update may not be necessary
|
// technically, as all properties are null, update may not be necessary
|
||||||
assertFalse( session.isDirty() ); // must be false to avoid unnecessary updates
|
assertFalse( session.isDirty() ); // must be false to avoid unnecessary updates
|
||||||
|
|
||||||
s.getTransaction().rollback();
|
s.getTransaction().rollback();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
s.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,20 +42,25 @@ public class EmptyInitializedCompositesDirtynessTest extends BaseCoreFunctionalT
|
||||||
@TestForIssue(jiraKey = "HHH-7610")
|
@TestForIssue(jiraKey = "HHH-7610")
|
||||||
public void testInitializedCompositesEmpty() {
|
public void testInitializedCompositesEmpty() {
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
s.getTransaction().begin();
|
try {
|
||||||
|
s.getTransaction().begin();
|
||||||
|
|
||||||
ComponentEmptyEmbeddedOwner owner = new ComponentEmptyEmbeddedOwner();
|
ComponentEmptyEmbeddedOwner owner = new ComponentEmptyEmbeddedOwner();
|
||||||
s.persist( owner );
|
s.persist( owner );
|
||||||
|
|
||||||
s.flush();
|
s.flush();
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
|
|
||||||
s.clear();
|
s.clear();
|
||||||
s.getTransaction().begin();
|
s.getTransaction().begin();
|
||||||
owner = (ComponentEmptyEmbeddedOwner) s.get( ComponentEmptyEmbeddedOwner.class, owner.getId() );
|
owner = (ComponentEmptyEmbeddedOwner) s.get( ComponentEmptyEmbeddedOwner.class, owner.getId() );
|
||||||
assertNotNull( owner.getEmbedded() );
|
assertNotNull( owner.getEmbedded() );
|
||||||
assertFalse( s.isDirty() );
|
assertFalse( s.isDirty() );
|
||||||
|
|
||||||
s.getTransaction().rollback();
|
s.getTransaction().rollback();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
s.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,23 +41,28 @@ public class EmptyInitializedCompositesTest extends BaseCoreFunctionalTestCase {
|
||||||
@TestForIssue(jiraKey = "HHH-7610")
|
@TestForIssue(jiraKey = "HHH-7610")
|
||||||
public void testCompositesEmpty() {
|
public void testCompositesEmpty() {
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
s.getTransaction().begin();
|
try {
|
||||||
|
s.getTransaction().begin();
|
||||||
|
|
||||||
ComponentEmptyEmbeddedOwner owner = new ComponentEmptyEmbeddedOwner();
|
ComponentEmptyEmbeddedOwner owner = new ComponentEmptyEmbeddedOwner();
|
||||||
s.persist( owner );
|
s.persist( owner );
|
||||||
|
|
||||||
s.flush();
|
s.flush();
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
|
|
||||||
s.clear();
|
s.clear();
|
||||||
s.getTransaction().begin();
|
s.getTransaction().begin();
|
||||||
owner = (ComponentEmptyEmbeddedOwner) s.get( ComponentEmptyEmbeddedOwner.class, owner.getId() );
|
owner = (ComponentEmptyEmbeddedOwner) s.get( ComponentEmptyEmbeddedOwner.class, owner.getId() );
|
||||||
assertNotNull( owner.getEmbedded() );
|
assertNotNull( owner.getEmbedded() );
|
||||||
assertFalse( s.isDirty() );
|
assertFalse( s.isDirty() );
|
||||||
|
|
||||||
owner.setEmbedded( null );
|
owner.setEmbedded( null );
|
||||||
assertFalse( s.isDirty() ); // must be false to avoid unnecessary updates
|
assertFalse( s.isDirty() ); // must be false to avoid unnecessary updates
|
||||||
|
|
||||||
s.getTransaction().rollback();
|
s.getTransaction().rollback();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
s.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.discriminator.joined;
|
package org.hibernate.test.discriminator.joined;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
import org.hibernate.testing.transaction.TransactionUtil;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -21,30 +21,20 @@ public class JoinedSubclassInheritanceTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String[] getMappings() {
|
protected String[] getMappings() {
|
||||||
return new String[] { "discriminator/joined/JoinedSubclassInheritance.hbm.xml" };
|
return new String[] {"discriminator/joined/JoinedSubclassInheritance.hbm.xml"};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConfiguredDiscriminatorValue() {
|
public void testConfiguredDiscriminatorValue() {
|
||||||
Session session = openSession();
|
final ChildEntity childEntity = new ChildEntity( 1, "Child" );
|
||||||
try {
|
TransactionUtil.doInHibernate( this::sessionFactory, session -> {
|
||||||
ChildEntity ce = new ChildEntity( 1, "Child" );
|
session.save( childEntity );
|
||||||
session.getTransaction().begin();
|
} );
|
||||||
session.save( ce );
|
|
||||||
session.getTransaction().commit();
|
|
||||||
session.clear();
|
|
||||||
|
|
||||||
ce = (ChildEntity) session.find( ChildEntity.class, 1 );
|
TransactionUtil.doInHibernate( this::sessionFactory, session -> {
|
||||||
|
ChildEntity ce = session.find( ChildEntity.class, 1 );
|
||||||
assertEquals( "ce", ce.getType() );
|
assertEquals( "ce", ce.getType() );
|
||||||
}
|
} );
|
||||||
catch ( Exception e ) {
|
|
||||||
if ( session.getTransaction().isActive() ) {
|
|
||||||
session.getTransaction().rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
session.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4053,6 +4053,7 @@ public class FooBarTest extends LegacyTestCase {
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
s.getTransaction().rollback();
|
s.getTransaction().rollback();
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
s.close();
|
s.close();
|
||||||
|
|
|
@ -24,7 +24,6 @@ import org.jboss.logging.Logger;
|
||||||
|
|
||||||
import org.hibernate.LockMode;
|
import org.hibernate.LockMode;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.Transaction;
|
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
import org.hibernate.loader.Loader;
|
import org.hibernate.loader.Loader;
|
||||||
import org.hibernate.query.Query;
|
import org.hibernate.query.Query;
|
||||||
|
@ -39,6 +38,7 @@ import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
import org.hibernate.testing.logger.LoggerInspectionRule;
|
import org.hibernate.testing.logger.LoggerInspectionRule;
|
||||||
import org.hibernate.testing.logger.Triggerable;
|
import org.hibernate.testing.logger.Triggerable;
|
||||||
|
import org.hibernate.testing.transaction.TransactionUtil;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
|
@ -61,27 +61,17 @@ public class LockNoneWarmingTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp(){
|
public void setUp() {
|
||||||
buildSessionFactory();
|
buildSessionFactory();
|
||||||
final Set messagesPrefixes = new HashSet<>( );
|
final Set messagesPrefixes = new HashSet<>();
|
||||||
messagesPrefixes.add( "HHH000444" );
|
messagesPrefixes.add( "HHH000444" );
|
||||||
messagesPrefixes.add( "HHH000445" );
|
messagesPrefixes.add( "HHH000445" );
|
||||||
triggerable = logInspection.watchForLogMessages( messagesPrefixes );
|
triggerable = logInspection.watchForLogMessages( messagesPrefixes );
|
||||||
try (Session s = openSession();) {
|
TransactionUtil.doInHibernate( this::sessionFactory, session -> {
|
||||||
Transaction tx = s.beginTransaction();
|
Item item = new Item();
|
||||||
try {
|
item.name = "ZZZZ";
|
||||||
Item item = new Item();
|
session.persist( item );
|
||||||
item.name = "ZZZZ";
|
} );
|
||||||
s.persist( item );
|
|
||||||
|
|
||||||
tx.commit();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
if ( tx.isActive() ) {
|
|
||||||
tx.rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
@ -12,7 +12,6 @@ import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.boot.MetadataSources;
|
import org.hibernate.boot.MetadataSources;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
|
@ -23,6 +22,7 @@ import org.hibernate.tool.schema.JdbcMetadaAccessStrategy;
|
||||||
|
|
||||||
import org.hibernate.testing.RequiresDialect;
|
import org.hibernate.testing.RequiresDialect;
|
||||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||||
|
import org.hibernate.testing.transaction.TransactionUtil;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -47,38 +47,16 @@ public class SynonymValidationTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
Session s = openSession();
|
TransactionUtil.doInHibernate( this::sessionFactory, session -> {
|
||||||
try {
|
session.createSQLQuery( "CREATE SYNONYM test_synonym FOR test_entity" ).executeUpdate();
|
||||||
s.getTransaction().begin();
|
} );
|
||||||
s.createSQLQuery( "CREATE SYNONYM test_synonym FOR test_entity" ).executeUpdate();
|
|
||||||
s.getTransaction().commit();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
if ( s.getTransaction().isActive() ) {
|
|
||||||
s.getTransaction().rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
Session s = openSession();
|
TransactionUtil.doInHibernate( this::sessionFactory, session -> {
|
||||||
try {
|
session.createSQLQuery( "DROP SYNONYM test_synonym FORCE" ).executeUpdate();
|
||||||
s.getTransaction().begin();
|
});
|
||||||
s.createSQLQuery( "DROP SYNONYM test_synonym FORCE" ).executeUpdate();
|
|
||||||
s.getTransaction().commit();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
if ( s.getTransaction().isActive() ) {
|
|
||||||
s.getTransaction().rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -12,7 +12,6 @@ import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.boot.MetadataSources;
|
import org.hibernate.boot.MetadataSources;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
|
@ -25,6 +24,7 @@ import org.hibernate.tool.schema.JdbcMetadaAccessStrategy;
|
||||||
import org.hibernate.testing.RequiresDialect;
|
import org.hibernate.testing.RequiresDialect;
|
||||||
import org.hibernate.testing.RequiresDialects;
|
import org.hibernate.testing.RequiresDialects;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
import org.hibernate.testing.transaction.TransactionUtil;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -46,38 +46,16 @@ public class ViewValidationTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
Session s = openSession();
|
TransactionUtil.doInHibernate( this::sessionFactory, session -> {
|
||||||
try {
|
session.createSQLQuery( "CREATE VIEW test_synonym AS SELECT * FROM test_entity" ).executeUpdate();
|
||||||
s.getTransaction().begin();
|
} );
|
||||||
s.createSQLQuery( "CREATE VIEW test_synonym AS SELECT * FROM test_entity" ).executeUpdate();
|
|
||||||
s.getTransaction().commit();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
if ( s.getTransaction().isActive() ) {
|
|
||||||
s.getTransaction().rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
Session s = openSession();
|
TransactionUtil.doInHibernate( this::sessionFactory, session -> {
|
||||||
try {
|
session.createSQLQuery( "DROP VIEW test_synonym CASCADE" ).executeUpdate();
|
||||||
s.getTransaction().begin();
|
} );
|
||||||
s.createSQLQuery( "DROP VIEW test_synonym CASCADE" ).executeUpdate();
|
|
||||||
s.getTransaction().commit();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
if ( s.getTransaction().isActive() ) {
|
|
||||||
s.getTransaction().rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue