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