HHH-10664 - Prep 6.0 feature branch - merge hibernate-entitymanager into hibernate-core (fix test failures)

This commit is contained in:
Steve Ebersole 2016-05-02 23:53:35 -05:00
parent 9ecb2a3deb
commit 71009d0da4
4 changed files with 41 additions and 15 deletions

View File

@ -24,6 +24,7 @@ import javax.persistence.FlushModeType;
import javax.persistence.LockModeType;
import javax.persistence.Parameter;
import javax.persistence.TemporalType;
import javax.persistence.TransactionRequiredException;
import org.hibernate.CacheMode;
import org.hibernate.Filter;
@ -1203,6 +1204,12 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
@SuppressWarnings("unchecked")
protected List<R> doList() {
if ( lockOptions.getLockMode() != null && lockOptions.getLockMode() != LockMode.NONE ) {
if ( !getProducer().isTransactionInProgress() ) {
throw new TransactionRequiredException( "no transaction is in progress" );
}
}
return getProducer().list(
queryParameterBindings.expandListValuedParameters( getQueryString(), getProducer() ),
getQueryParameters()
@ -1234,6 +1241,13 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
@Override
public int executeUpdate() throws HibernateException {
if ( ! getProducer().isTransactionInProgress() ) {
throw getProducer().getExceptionConverter().convert(
new TransactionRequiredException(
"Executing an update/delete query"
)
);
}
beforeQuery();
try {
return doExecuteUpdate();

View File

@ -6,18 +6,21 @@
*/
package org.hibernate.test.enums;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.sql.Connection;
import java.sql.SQLException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.jdbc.Work;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
@ -57,7 +60,9 @@ public class UnspecifiedEnumTypeTest extends BaseCoreFunctionalTestCase {
@After
public void dropTable() {
Session session = openSession();
dropTable( session );
session.close();
}
@Test
@ -71,10 +76,13 @@ public class UnspecifiedEnumTypeTest extends BaseCoreFunctionalTestCase {
}
private void executeUpdateSafety(Session session, String query) {
try {
session.createSQLQuery( query ).executeUpdate();
}
catch ( Exception e ) {
}
session.doWork(
new Work() {
@Override
public void execute(Connection connection) throws SQLException {
connection.createStatement().execute( query );
}
}
);
}
}

View File

@ -7,13 +7,11 @@
package org.hibernate.test.sql.syncSpace;
import java.util.Map;
import javax.persistence.Cacheable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
@ -80,7 +78,9 @@ public class NativeQuerySyncSpaceCachingTest extends BaseNonConfigCoreFunctional
assertTrue( sessionFactory().getCache().containsEntity( Customer.class, 1 ) );
Session session = openSession();
session.beginTransaction();
session.createSQLQuery( "update Address set id = id" ).executeUpdate();
session.getTransaction().commit();
session.close();
// NOTE false here because executeUpdate is different than selects
@ -92,7 +92,9 @@ public class NativeQuerySyncSpaceCachingTest extends BaseNonConfigCoreFunctional
assertTrue( sessionFactory().getCache().containsEntity( Customer.class, 1 ) );
Session session = openSession();
session.beginTransaction();
session.createSQLQuery( "update Address set id = id" ).addSynchronizedEntityClass( Address.class ).executeUpdate();
session.getTransaction().commit();
session.close();
assertTrue( sessionFactory().getCache().containsEntity( Customer.class, 1 ) );
@ -114,7 +116,9 @@ public class NativeQuerySyncSpaceCachingTest extends BaseNonConfigCoreFunctional
assertTrue( sessionFactory().getCache().containsEntity( Customer.class, 1 ) );
Session session = openSession();
session.beginTransaction();
session.createSQLQuery( "update Customer set id = id" ).executeUpdate();
session.getTransaction().commit();
session.close();
// NOTE false here because executeUpdate is different than selects
@ -126,7 +130,9 @@ public class NativeQuerySyncSpaceCachingTest extends BaseNonConfigCoreFunctional
assertTrue( sessionFactory().getCache().containsEntity( Customer.class, 1 ) );
Session session = openSession();
session.beginTransaction();
session.createSQLQuery( "update Customer set id = id" ).addSynchronizedEntityClass( Customer.class ).executeUpdate();
session.getTransaction().commit();
session.close();
assertFalse( sessionFactory().getCache().containsEntity( Customer.class, 1 ) );

View File

@ -96,7 +96,7 @@ public class SynchronizationTypeTest extends BaseEntityManagerFunctionalTestCase
assertTrue( session.isOpen() );
entityManager.close();
assertFalse( entityManager.isOpen() );
assertTrue( session.isOpen() );
assertFalse( session.isOpen() );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertFalse( entityManager.isOpen() );
@ -111,10 +111,8 @@ public class SynchronizationTypeTest extends BaseEntityManagerFunctionalTestCase
assertFalse( "setup problem", JtaStatusHelper.isActive( TestingJtaPlatformImpl.INSTANCE.getTransactionManager() ) );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
assertTrue(
"setup problem", JtaStatusHelper.isActive(
TestingJtaPlatformImpl.INSTANCE
.getTransactionManager()
)
"setup problem",
JtaStatusHelper.isActive( TestingJtaPlatformImpl.INSTANCE.getTransactionManager() )
);
EntityManager entityManager = entityManagerFactory().createEntityManager( SynchronizationType.UNSYNCHRONIZED, null );