HHH-13493 - For a native query, the SessionImpl class does not call applyQuerySettingsAndHints
This commit is contained in:
parent
a92cd6c9b9
commit
9a627c30fe
|
@ -632,6 +632,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
||||||
getQueryPlan( queryString, false ).getParameterMetadata(),
|
getQueryPlan( queryString, false ).getParameterMetadata(),
|
||||||
queryString
|
queryString
|
||||||
);
|
);
|
||||||
|
applyQuerySettingsAndHints( query );
|
||||||
query.setHibernateFlushMode( queryDefinition.getFlushMode() );
|
query.setHibernateFlushMode( queryDefinition.getFlushMode() );
|
||||||
query.setComment( queryDefinition.getComment() != null ? queryDefinition.getComment() : queryDefinition.getName() );
|
query.setComment( queryDefinition.getComment() != null ? queryDefinition.getComment() : queryDefinition.getName() );
|
||||||
if ( queryDefinition.getLockOptions() != null ) {
|
if ( queryDefinition.getLockOptions() != null ) {
|
||||||
|
@ -639,7 +640,6 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
||||||
}
|
}
|
||||||
|
|
||||||
initQueryFromNamedDefinition( query, queryDefinition );
|
initQueryFromNamedDefinition( query, queryDefinition );
|
||||||
// applyQuerySettingsAndHints( query );
|
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
@ -660,10 +660,10 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
||||||
this,
|
this,
|
||||||
parameterMetadata
|
parameterMetadata
|
||||||
);
|
);
|
||||||
|
applyQuerySettingsAndHints( query );
|
||||||
query.setComment( queryDefinition.getComment() != null ? queryDefinition.getComment() : queryDefinition.getName() );
|
query.setComment( queryDefinition.getComment() != null ? queryDefinition.getComment() : queryDefinition.getName() );
|
||||||
|
|
||||||
initQueryFromNamedDefinition( query, queryDefinition );
|
initQueryFromNamedDefinition( query, queryDefinition );
|
||||||
applyQuerySettingsAndHints( query );
|
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
@ -709,8 +709,8 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
||||||
getQueryPlan( queryString, false ).getParameterMetadata(),
|
getQueryPlan( queryString, false ).getParameterMetadata(),
|
||||||
queryString
|
queryString
|
||||||
);
|
);
|
||||||
query.setComment( queryString );
|
|
||||||
applyQuerySettingsAndHints( query );
|
applyQuerySettingsAndHints( query );
|
||||||
|
query.setComment( queryString );
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
catch (RuntimeException e) {
|
catch (RuntimeException e) {
|
||||||
|
@ -919,6 +919,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
||||||
if ( Tuple.class.equals( resultType ) ) {
|
if ( Tuple.class.equals( resultType ) ) {
|
||||||
query.setResultTransformer( new NativeQueryTupleTransformer() );
|
query.setResultTransformer( new NativeQueryTupleTransformer() );
|
||||||
}
|
}
|
||||||
|
applyQuerySettingsAndHints( query );
|
||||||
query.setHibernateFlushMode( queryDefinition.getFlushMode() );
|
query.setHibernateFlushMode( queryDefinition.getFlushMode() );
|
||||||
query.setComment( queryDefinition.getComment() != null ? queryDefinition.getComment() : queryDefinition.getName() );
|
query.setComment( queryDefinition.getComment() != null ? queryDefinition.getComment() : queryDefinition.getName() );
|
||||||
if ( queryDefinition.getLockOptions() != null ) {
|
if ( queryDefinition.getLockOptions() != null ) {
|
||||||
|
@ -926,7 +927,6 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
||||||
}
|
}
|
||||||
|
|
||||||
initQueryFromNamedDefinition( query, queryDefinition );
|
initQueryFromNamedDefinition( query, queryDefinition );
|
||||||
applyQuerySettingsAndHints( query );
|
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
@ -1070,6 +1070,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
||||||
getFactory().getQueryPlanCache().getSQLParameterMetadata( queryString, isOrdinalParameterZeroBased )
|
getFactory().getQueryPlanCache().getSQLParameterMetadata( queryString, isOrdinalParameterZeroBased )
|
||||||
);
|
);
|
||||||
query.setComment( "dynamic native SQL query" );
|
query.setComment( "dynamic native SQL query" );
|
||||||
|
applyQuerySettingsAndHints( query );
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
catch ( RuntimeException he ) {
|
catch ( RuntimeException he ) {
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
|
*/
|
||||||
|
package org.hibernate.jpa.test.lock;
|
||||||
|
|
||||||
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
|
import org.hibernate.dialect.PostgreSQL82Dialect;
|
||||||
|
import org.hibernate.jpa.QueryHints;
|
||||||
|
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
import org.hibernate.query.NativeQuery;
|
||||||
|
import org.hibernate.testing.RequiresDialect;
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.hibernate.testing.util.ExceptionUtil;
|
||||||
|
import org.hibernate.type.IntegerType;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Vlad Mihalcea
|
||||||
|
*/
|
||||||
|
@RequiresDialect(PostgreSQL82Dialect.class)
|
||||||
|
@TestForIssue( jiraKey = "HHH-13493")
|
||||||
|
public class NativeSQLQueryTimeoutTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Override
|
||||||
|
protected void addConfigOptions(Map options) {
|
||||||
|
options.put( QueryHints.SPEC_HINT_TIMEOUT, "500" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test(){
|
||||||
|
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||||
|
try {
|
||||||
|
entityManager.createNativeQuery(
|
||||||
|
"select 1 " +
|
||||||
|
"from pg_sleep(2) "
|
||||||
|
)
|
||||||
|
.getResultList();
|
||||||
|
|
||||||
|
fail("Should have thrown lock timeout exception!");
|
||||||
|
} catch (Exception expected) {
|
||||||
|
assertTrue(
|
||||||
|
ExceptionUtil.rootCause(expected)
|
||||||
|
.getMessage().contains("canceling statement due to user request")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class[] getAnnotatedClasses() {
|
||||||
|
return new Class[] {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue