HHH-10664 - Prep 6.0 feature branch - merge hibernate-entitymanager into hibernate-core (fix test failures)
This commit is contained in:
parent
1c1783e90f
commit
9ecb2a3deb
|
@ -61,11 +61,13 @@ public class InterceptorTest extends BaseEntityManagerFunctionalTestCase {
|
|||
.withOptions()
|
||||
.interceptor(new LoggingInterceptor() )
|
||||
.openSession();
|
||||
session.getTransaction().begin();
|
||||
|
||||
Customer customer = session.get( Customer.class, customerId );
|
||||
customer.setName( "Mr. John Doe" );
|
||||
//Entity Customer#1 changed from [John Doe, 0] to [Mr. John Doe, 0]
|
||||
session.flush();
|
||||
|
||||
session.getTransaction().commit();
|
||||
//end::events-interceptors-session-scope-example[]
|
||||
session.close();
|
||||
}
|
||||
|
@ -84,11 +86,12 @@ public class InterceptorTest extends BaseEntityManagerFunctionalTestCase {
|
|||
.build();
|
||||
//end::events-interceptors-session-factory-scope-example[]
|
||||
Session session = sessionFactory.openSession();
|
||||
session.getTransaction().begin();
|
||||
|
||||
Customer customer = session.get( Customer.class, customerId );
|
||||
customer.setName( "Mr. John Doe" );
|
||||
//Entity Customer#1 changed from [John Doe, 0] to [Mr. John Doe, 0]
|
||||
session.flush();
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
sessionFactory.close();
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ public class AutoFlushTest extends BaseEntityManagerFunctionalTestCase {
|
|||
assertTrue(((Number) session
|
||||
.createSQLQuery( "select count(*) from Person")
|
||||
.uniqueResult()).intValue() == 0 );
|
||||
//end::flushing-auto-flush-sql-native-example[]
|
||||
//end::flushing-auto-flush-sql-native-example[\]
|
||||
} );
|
||||
}
|
||||
|
||||
|
|
|
@ -35,9 +35,6 @@ import javax.persistence.criteria.Selection;
|
|||
import javax.persistence.criteria.SetJoin;
|
||||
import javax.persistence.criteria.Subquery;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.internal.SessionFactoryImpl;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
|
@ -84,8 +81,6 @@ import org.hibernate.query.criteria.internal.predicate.IsEmptyPredicate;
|
|||
import org.hibernate.query.criteria.internal.predicate.LikePredicate;
|
||||
import org.hibernate.query.criteria.internal.predicate.MemberOfPredicate;
|
||||
import org.hibernate.query.criteria.internal.predicate.NullnessPredicate;
|
||||
import org.hibernate.type.SerializableType;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* Hibernate implementation of the JPA {@link CriteriaBuilder} contract.
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.hibernate.engine.spi.SessionImplementor;
|
|||
import org.hibernate.jpa.spi.HibernateEntityManagerImplementor;
|
||||
import org.hibernate.query.criteria.internal.compile.CompilableCriteria;
|
||||
import org.hibernate.query.criteria.internal.compile.CriteriaInterpretation;
|
||||
import org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter;
|
||||
import org.hibernate.query.criteria.internal.compile.ImplicitParameterBinding;
|
||||
import org.hibernate.query.criteria.internal.compile.InterpretedParameterMetadata;
|
||||
import org.hibernate.query.criteria.internal.compile.RenderingContext;
|
||||
|
@ -370,13 +371,12 @@ public class CriteriaQueryImpl<T> extends AbstractNode implements CriteriaQuery<
|
|||
implicitParameterBinding.bind( jpaqlQuery );
|
||||
}
|
||||
|
||||
// return new CriteriaQueryTypeQueryAdapter(
|
||||
// entityManager,
|
||||
// jpaqlQuery,
|
||||
// parameterMetadata.explicitParameterInfoMap()
|
||||
// );
|
||||
return new CriteriaQueryTypeQueryAdapter(
|
||||
entityManager,
|
||||
jpaqlQuery,
|
||||
parameterMetadata.explicitParameterInfoMap()
|
||||
);
|
||||
|
||||
return jpaqlQuery;
|
||||
}
|
||||
|
||||
private Map<String, Class> extractTypeMap(List<ImplicitParameterBinding> implicitParameterBindings) {
|
||||
|
|
|
@ -16,17 +16,27 @@ import javax.persistence.FlushModeType;
|
|||
import javax.persistence.LockModeType;
|
||||
import javax.persistence.Parameter;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.persistence.criteria.ParameterExpression;
|
||||
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.jpa.HibernateQuery;
|
||||
import org.hibernate.query.Query;
|
||||
import org.hibernate.query.internal.AbstractProducedQuery;
|
||||
import org.hibernate.query.spi.QueryImplementor;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* <strong>Make this go away in 6.0</strong> :)
|
||||
* <p/>
|
||||
* Needed because atm we render a JPA Criteria query into a HQL/JPQL query String and some metadata, and then
|
||||
* compile into a Query. This class wraps the compiled HQL/JPQL query and adds an extra layer of metadata.
|
||||
* <p/>
|
||||
* But the move to SQM in 6.0 allows us to do away with the "wrapping".
|
||||
*
|
||||
* Essentially
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, HibernateQuery {
|
||||
public class CriteriaQueryTypeQueryAdapter<X> extends AbstractProducedQuery<X> implements QueryImplementor<X> {
|
||||
private final SessionImplementor entityManager;
|
||||
private final QueryImplementor<X> jpqlQuery;
|
||||
private final Map<ParameterExpression<?>, ExplicitParameterInfo<?>> explicitParameterInfoMap;
|
||||
|
@ -35,16 +45,12 @@ public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, Hibernat
|
|||
SessionImplementor entityManager,
|
||||
QueryImplementor<X> jpqlQuery,
|
||||
Map<ParameterExpression<?>, ExplicitParameterInfo<?>> explicitParameterInfoMap) {
|
||||
super( entityManager, jpqlQuery.getParameterMetadata() );
|
||||
this.entityManager = entityManager;
|
||||
this.jpqlQuery = jpqlQuery;
|
||||
this.explicitParameterInfoMap = explicitParameterInfoMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryImplementor getHibernateQuery() {
|
||||
return jpqlQuery;
|
||||
}
|
||||
|
||||
public List<X> getResultList() {
|
||||
return jpqlQuery.getResultList();
|
||||
}
|
||||
|
@ -57,7 +63,7 @@ public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, Hibernat
|
|||
return jpqlQuery.getMaxResults();
|
||||
}
|
||||
|
||||
public TypedQuery<X> setMaxResults(int i) {
|
||||
public QueryImplementor<X> setMaxResults(int i) {
|
||||
jpqlQuery.setMaxResults( i );
|
||||
return this;
|
||||
}
|
||||
|
@ -66,7 +72,7 @@ public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, Hibernat
|
|||
return jpqlQuery.getFirstResult();
|
||||
}
|
||||
|
||||
public TypedQuery<X> setFirstResult(int i) {
|
||||
public QueryImplementor<X> setFirstResult(int i) {
|
||||
jpqlQuery.setFirstResult( i );
|
||||
return this;
|
||||
}
|
||||
|
@ -75,16 +81,31 @@ public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, Hibernat
|
|||
return jpqlQuery.getHints();
|
||||
}
|
||||
|
||||
public TypedQuery<X> setHint(String name, Object value) {
|
||||
public QueryImplementor<X> setHint(String name, Object value) {
|
||||
jpqlQuery.setHint( name, value );
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isNativeQuery() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQueryString() {
|
||||
return jpqlQuery.getQueryString();
|
||||
}
|
||||
|
||||
public FlushModeType getFlushMode() {
|
||||
return jpqlQuery.getFlushMode();
|
||||
}
|
||||
|
||||
public TypedQuery<X> setFlushMode(FlushModeType flushModeType) {
|
||||
@Override
|
||||
public Type[] getReturnTypes() {
|
||||
return jpqlQuery.getReturnTypes();
|
||||
}
|
||||
|
||||
public QueryImplementor<X> setFlushMode(FlushModeType flushModeType) {
|
||||
jpqlQuery.setFlushMode( flushModeType );
|
||||
return this;
|
||||
}
|
||||
|
@ -93,11 +114,26 @@ public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, Hibernat
|
|||
return jpqlQuery.getLockMode();
|
||||
}
|
||||
|
||||
public TypedQuery<X> setLockMode(LockModeType lockModeType) {
|
||||
public QueryImplementor<X> setLockMode(LockModeType lockModeType) {
|
||||
jpqlQuery.setLockMode( lockModeType );
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<X> setEntity(int position, Object val) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<X> setEntity(String name, Object val) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getReturnAliases() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public Set<Parameter<?>> getParameters() {
|
||||
entityManager.checkOpen( false );
|
||||
|
@ -142,7 +178,7 @@ public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, Hibernat
|
|||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public <T> TypedQuery<X> setParameter(Parameter<T> param, T t) {
|
||||
public <T> QueryImplementor<X> setParameter(Parameter<T> param, T t) {
|
||||
entityManager.checkOpen( false );
|
||||
final ExplicitParameterInfo parameterInfo = resolveParameterInfo( param );
|
||||
if ( parameterInfo.isNamed() ) {
|
||||
|
@ -155,7 +191,7 @@ public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, Hibernat
|
|||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public TypedQuery<X> setParameter(Parameter<Calendar> param, Calendar calendar, TemporalType temporalType) {
|
||||
public QueryImplementor<X> setParameter(Parameter<Calendar> param, Calendar calendar, TemporalType temporalType) {
|
||||
entityManager.checkOpen( false );
|
||||
final ExplicitParameterInfo parameterInfo = resolveParameterInfo( param );
|
||||
if ( parameterInfo.isNamed() ) {
|
||||
|
@ -168,7 +204,7 @@ public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, Hibernat
|
|||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public TypedQuery<X> setParameter(Parameter<Date> param, Date date, TemporalType temporalType) {
|
||||
public QueryImplementor<X> setParameter(Parameter<Date> param, Date date, TemporalType temporalType) {
|
||||
entityManager.checkOpen( false );
|
||||
final ExplicitParameterInfo parameterInfo = resolveParameterInfo( param );
|
||||
if ( parameterInfo.isNamed() ) {
|
||||
|
@ -219,7 +255,7 @@ public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, Hibernat
|
|||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public TypedQuery<X> setParameter(String name, Object value) {
|
||||
public QueryImplementor<X> setParameter(String name, Object value) {
|
||||
entityManager.checkOpen( true );
|
||||
ExplicitParameterInfo parameterInfo = locateParameterByName( name );
|
||||
parameterInfo.validateBindValue( value );
|
||||
|
@ -228,7 +264,7 @@ public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, Hibernat
|
|||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public TypedQuery<X> setParameter(String name, Calendar calendar, TemporalType temporalType) {
|
||||
public QueryImplementor<X> setParameter(String name, Calendar calendar, TemporalType temporalType) {
|
||||
entityManager.checkOpen( true );
|
||||
ExplicitParameterInfo parameterInfo = locateParameterByName( name );
|
||||
parameterInfo.validateCalendarBind();
|
||||
|
@ -237,7 +273,7 @@ public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, Hibernat
|
|||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public TypedQuery<X> setParameter(String name, Date date, TemporalType temporalType) {
|
||||
public QueryImplementor<X> setParameter(String name, Date date, TemporalType temporalType) {
|
||||
entityManager.checkOpen( true );
|
||||
ExplicitParameterInfo parameterInfo = locateParameterByName( name );
|
||||
parameterInfo.validateDateBind();
|
||||
|
@ -252,15 +288,15 @@ public class CriteriaQueryTypeQueryAdapter<X> implements TypedQuery<X>, Hibernat
|
|||
throw new IllegalStateException( "Typed criteria queries do not support executeUpdate" );
|
||||
}
|
||||
|
||||
public TypedQuery<X> setParameter(int i, Object o) {
|
||||
public QueryImplementor<X> setParameter(int i, Object o) {
|
||||
throw new IllegalArgumentException( "Criteria queries do not support positioned parameters" );
|
||||
}
|
||||
|
||||
public TypedQuery<X> setParameter(int i, Calendar calendar, TemporalType temporalType) {
|
||||
public QueryImplementor<X> setParameter(int i, Calendar calendar, TemporalType temporalType) {
|
||||
throw new IllegalArgumentException( "Criteria queries do not support positioned parameters" );
|
||||
}
|
||||
|
||||
public TypedQuery<X> setParameter(int i, Date date, TemporalType temporalType) {
|
||||
public QueryImplementor<X> setParameter(int i, Date date, TemporalType temporalType) {
|
||||
throw new IllegalArgumentException( "Criteria queries do not support positioned parameters" );
|
||||
}
|
||||
|
||||
|
|
|
@ -103,7 +103,8 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
|||
|
||||
private ResultTransformer resultTransformer;
|
||||
private RowSelection queryOptions = new RowSelection();
|
||||
private HQLQueryPlan entityGraphHintedQueryPlan;
|
||||
|
||||
private EntityGraphQueryHint entityGraphQueryHint;
|
||||
|
||||
private Object optionalObject;
|
||||
private Serializable optionalId;
|
||||
|
@ -487,14 +488,14 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public QueryImplementor setParameter(Parameter param, Calendar value, TemporalType temporalType) {
|
||||
public QueryImplementor setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType) {
|
||||
queryParameterBindings.getBinding( (QueryParameter) param ).setBindValue( value, temporalType );
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public QueryImplementor setParameter(Parameter param, Date value, TemporalType temporalType) {
|
||||
public QueryImplementor setParameter(Parameter<Date> param, Date value, TemporalType temporalType) {
|
||||
queryParameterBindings.getBinding( (QueryParameter) param ).setBindValue( value, temporalType );
|
||||
return this;
|
||||
}
|
||||
|
@ -1009,19 +1010,8 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
|||
*
|
||||
* @param hint The entity graph hint object
|
||||
*/
|
||||
public void applyEntityGraphQueryHint(EntityGraphQueryHint hint) {
|
||||
queryParameterBindings.verifyParametersBound( false );
|
||||
|
||||
// todo : ideally we'd update the instance state related to queryString but that is final atm
|
||||
|
||||
final String expandedQuery = queryParameterBindings.expandListValuedParameters( getQueryString(), getProducer() );
|
||||
this.entityGraphHintedQueryPlan = new HQLQueryPlan(
|
||||
expandedQuery,
|
||||
false,
|
||||
getProducer().getLoadQueryInfluencers().getEnabledFilters(),
|
||||
getProducer().getFactory(),
|
||||
hint
|
||||
);
|
||||
protected void applyEntityGraphQueryHint(EntityGraphQueryHint hint) {
|
||||
this.entityGraphQueryHint = hint;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1057,6 +1047,25 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
|||
}
|
||||
|
||||
public QueryParameters getQueryParameters() {
|
||||
final HQLQueryPlan entityGraphHintedQueryPlan;
|
||||
if ( entityGraphQueryHint == null) {
|
||||
entityGraphHintedQueryPlan = null;
|
||||
}
|
||||
else {
|
||||
queryParameterBindings.verifyParametersBound( false );
|
||||
|
||||
// todo : ideally we'd update the instance state related to queryString but that is final atm
|
||||
|
||||
final String expandedQuery = queryParameterBindings.expandListValuedParameters( getQueryString(), getProducer() );
|
||||
entityGraphHintedQueryPlan = new HQLQueryPlan(
|
||||
expandedQuery,
|
||||
false,
|
||||
getProducer().getLoadQueryInfluencers().getEnabledFilters(),
|
||||
getProducer().getFactory(),
|
||||
entityGraphQueryHint
|
||||
);
|
||||
}
|
||||
|
||||
QueryParameters queryParameters = new QueryParameters(
|
||||
getPositionalParameterTypes(),
|
||||
getPositionalParameterValues(),
|
||||
|
|
|
@ -213,6 +213,7 @@ public class NativeQueryImpl<T> extends AbstractProducedQuery<T> implements Nati
|
|||
|
||||
super.beforeQuery();
|
||||
|
||||
|
||||
if ( getSynchronizedQuerySpaces() != null && !getSynchronizedQuerySpaces().isEmpty() ) {
|
||||
// The application defined query spaces on the Hibernate native SQLQuery which means the query will already
|
||||
// perform a partial flush according to the defined query spaces, no need to do a full flush.
|
||||
|
@ -237,9 +238,11 @@ public class NativeQueryImpl<T> extends AbstractProducedQuery<T> implements Nati
|
|||
}
|
||||
|
||||
if ( effectiveFlushMode != FlushMode.MANUAL ) {
|
||||
if ( getProducer().getFactory().getSessionFactoryOptions().isJpaBootstrap() ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ package org.hibernate.resource.jdbc.internal;
|
|||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.hibernate.ResourceClosedException;
|
||||
import org.hibernate.TransactionException;
|
||||
import org.hibernate.resource.jdbc.ResourceRegistry;
|
||||
import org.hibernate.resource.jdbc.spi.LogicalConnectionImplementor;
|
||||
|
@ -35,7 +34,7 @@ public abstract class AbstractLogicalConnectionImplementor implements LogicalCon
|
|||
|
||||
protected void errorIfClosed() {
|
||||
if ( !isOpen() ) {
|
||||
throw new ResourceClosedException( this.toString() + " is closed" );
|
||||
throw new IllegalStateException( this.toString() + " is closed" );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -161,7 +161,6 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase
|
|||
}
|
||||
catch ( IllegalStateException e ) {
|
||||
//success
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue