Move tests to orm/test and fix query cache stats, native query variable substitution and named query support as loader
This commit is contained in:
parent
3e32e15c0a
commit
5b0b822717
|
@ -50,20 +50,13 @@ ext {
|
||||||
'jdbc.url' : 'jdbc:postgresql://127.0.0.1/hibernate_orm_test?preparedStatementCacheQueries=0'
|
'jdbc.url' : 'jdbc:postgresql://127.0.0.1/hibernate_orm_test?preparedStatementCacheQueries=0'
|
||||||
],
|
],
|
||||||
pgsql_ci : [
|
pgsql_ci : [
|
||||||
'db.dialect' : 'org.hibernate.dialect.PostgreSQL95Dialect',
|
'db.dialect' : 'org.hibernate.dialect.PostgreSQLDialect',
|
||||||
'jdbc.driver': 'org.postgresql.Driver',
|
'jdbc.driver': 'org.postgresql.Driver',
|
||||||
'jdbc.user' : 'hibernate_orm_test',
|
'jdbc.user' : 'hibernate_orm_test',
|
||||||
'jdbc.pass' : 'hibernate_orm_test',
|
'jdbc.pass' : 'hibernate_orm_test',
|
||||||
// Disable prepared statement caching due to https://www.postgresql.org/message-id/CAEcMXhmmRd4-%2BNQbnjDT26XNdUoXdmntV9zdr8%3DTu8PL9aVCYg%40mail.gmail.com
|
// Disable prepared statement caching due to https://www.postgresql.org/message-id/CAEcMXhmmRd4-%2BNQbnjDT26XNdUoXdmntV9zdr8%3DTu8PL9aVCYg%40mail.gmail.com
|
||||||
'jdbc.url' : 'jdbc:postgresql://' + dbHost + '/hibernate_orm_test?preparedStatementCacheQueries=0'
|
'jdbc.url' : 'jdbc:postgresql://' + dbHost + '/hibernate_orm_test?preparedStatementCacheQueries=0'
|
||||||
],
|
],
|
||||||
pgsql_ci : [
|
|
||||||
'db.dialect' : 'org.hibernate.dialect.PostgreSQLDialect',
|
|
||||||
'jdbc.driver': 'org.postgresql.Driver',
|
|
||||||
'jdbc.user' : 'hibernate_orm_test',
|
|
||||||
'jdbc.pass' : 'hibernate_orm_test',
|
|
||||||
'jdbc.url' : 'jdbc:postgresql://' + dbHost + '/hibernate_orm_test'
|
|
||||||
],
|
|
||||||
mysql : [
|
mysql : [
|
||||||
'db.dialect' : 'org.hibernate.dialect.MySQLDialect',
|
'db.dialect' : 'org.hibernate.dialect.MySQLDialect',
|
||||||
'jdbc.driver': 'com.mysql.jdbc.Driver',
|
'jdbc.driver': 'com.mysql.jdbc.Driver',
|
||||||
|
|
|
@ -136,6 +136,13 @@ public interface Metadata extends Mapping {
|
||||||
*/
|
*/
|
||||||
void visitNamedNativeQueryDefinitions(Consumer<NamedNativeQueryDefinition> definitionConsumer);
|
void visitNamedNativeQueryDefinitions(Consumer<NamedNativeQueryDefinition> definitionConsumer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve named procedure metadata.
|
||||||
|
*
|
||||||
|
* @return The named procedure metadata, or {@code null}
|
||||||
|
*/
|
||||||
|
NamedProcedureCallDefinition getNamedProcedureCallMapping(String name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visit all named callable query definitions
|
* Visit all named callable query definitions
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -634,6 +634,11 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
|
||||||
// Named stored-procedure handling
|
// Named stored-procedure handling
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NamedProcedureCallDefinition getNamedProcedureCallMapping(String name) {
|
||||||
|
return namedProcedureCallMap.get( name );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitNamedProcedureCallDefinition(Consumer<NamedProcedureCallDefinition> definitionConsumer) {
|
public void visitNamedProcedureCallDefinition(Consumer<NamedProcedureCallDefinition> definitionConsumer) {
|
||||||
namedProcedureCallMap.values().forEach( definitionConsumer );
|
namedProcedureCallMap.values().forEach( definitionConsumer );
|
||||||
|
|
|
@ -251,6 +251,11 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
||||||
namedNativeQueryMap.values().forEach( definitionConsumer );
|
namedNativeQueryMap.values().forEach( definitionConsumer );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NamedProcedureCallDefinition getNamedProcedureCallMapping(String name) {
|
||||||
|
return namedProcedureCallMap.get( name );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitNamedProcedureCallDefinition(Consumer<NamedProcedureCallDefinition> definitionConsumer) {
|
public void visitNamedProcedureCallDefinition(Consumer<NamedProcedureCallDefinition> definitionConsumer) {
|
||||||
namedProcedureCallMap.values().forEach( definitionConsumer );
|
namedProcedureCallMap.values().forEach( definitionConsumer );
|
||||||
|
|
|
@ -139,6 +139,11 @@ public abstract class AbstractDelegatingMetadata implements MetadataImplementor
|
||||||
delegate.visitNamedNativeQueryDefinitions( definitionConsumer );
|
delegate.visitNamedNativeQueryDefinitions( definitionConsumer );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NamedProcedureCallDefinition getNamedProcedureCallMapping(String name) {
|
||||||
|
return delegate.getNamedProcedureCallMapping( name );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitNamedProcedureCallDefinition(Consumer<NamedProcedureCallDefinition> definitionConsumer) {
|
public void visitNamedProcedureCallDefinition(Consumer<NamedProcedureCallDefinition> definitionConsumer) {
|
||||||
delegate.visitNamedProcedureCallDefinition( definitionConsumer );
|
delegate.visitNamedProcedureCallDefinition( definitionConsumer );
|
||||||
|
|
|
@ -795,7 +795,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
||||||
|
|
||||||
if ( namedHqlDescriptor != null ) {
|
if ( namedHqlDescriptor != null ) {
|
||||||
HqlQueryImplementor query = namedHqlDescriptor.toQuery( this, resultType );
|
HqlQueryImplementor query = namedHqlDescriptor.toQuery( this, resultType );
|
||||||
query.setComment( "dynamic native SQL query" );
|
query.setComment( "dynamic HQL query" );
|
||||||
applyQuerySettingsAndHints( query );
|
applyQuerySettingsAndHints( query );
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,6 +111,7 @@ import org.hibernate.persister.entity.Loadable;
|
||||||
import org.hibernate.procedure.spi.ProcedureCallImplementor;
|
import org.hibernate.procedure.spi.ProcedureCallImplementor;
|
||||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||||
import org.hibernate.proxy.HibernateProxyHelper;
|
import org.hibernate.proxy.HibernateProxyHelper;
|
||||||
|
import org.hibernate.query.QueryLogging;
|
||||||
import org.hibernate.query.hql.spi.HqlQueryImplementor;
|
import org.hibernate.query.hql.spi.HqlQueryImplementor;
|
||||||
import org.hibernate.query.spi.QueryEngine;
|
import org.hibernate.query.spi.QueryEngine;
|
||||||
import org.hibernate.query.spi.QueryImplementor;
|
import org.hibernate.query.spi.QueryImplementor;
|
||||||
|
@ -312,7 +313,18 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
|
||||||
this.queryEngine.prepare( this, bootMetamodel, bootstrapContext );
|
this.queryEngine.prepare( this, bootMetamodel, bootstrapContext );
|
||||||
|
|
||||||
if ( options.isNamedQueryStartupCheckingEnabled() ) {
|
if ( options.isNamedQueryStartupCheckingEnabled() ) {
|
||||||
queryEngine.getNamedObjectRepository().checkNamedQueries( queryEngine );
|
final Map<String, HibernateException> errors = queryEngine.getNamedObjectRepository().checkNamedQueries( queryEngine );
|
||||||
|
|
||||||
|
if ( !errors.isEmpty() ) {
|
||||||
|
StringBuilder failingQueries = new StringBuilder( "Errors in named queries: " );
|
||||||
|
String sep = "";
|
||||||
|
for ( Map.Entry<String, HibernateException> entry : errors.entrySet() ) {
|
||||||
|
QueryLogging.QUERY_MESSAGE_LOGGER.namedQueryError( entry.getKey(), entry.getValue() );
|
||||||
|
failingQueries.append( sep ).append( entry.getKey() );
|
||||||
|
sep = ", ";
|
||||||
|
}
|
||||||
|
throw new HibernateException( failingQueries.toString() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SchemaManagementToolCoordinator.process(
|
SchemaManagementToolCoordinator.process(
|
||||||
|
@ -814,7 +826,7 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
|
||||||
cacheAccess.close();
|
cacheAccess.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( runtimeMetamodels != null ) {
|
if ( runtimeMetamodels != null && runtimeMetamodels.getMappingMetamodel() != null ) {
|
||||||
final JdbcConnectionAccess jdbcConnectionAccess = jdbcServices.getBootstrapJdbcConnectionAccess();
|
final JdbcConnectionAccess jdbcConnectionAccess = jdbcServices.getBootstrapJdbcConnectionAccess();
|
||||||
runtimeMetamodels.getMappingMetamodel().visitEntityDescriptors(
|
runtimeMetamodels.getMappingMetamodel().visitEntityDescriptors(
|
||||||
entityPersister -> {
|
entityPersister -> {
|
||||||
|
|
|
@ -7,15 +7,12 @@
|
||||||
package org.hibernate.loader.ast.internal;
|
package org.hibernate.loader.ast.internal;
|
||||||
|
|
||||||
import org.hibernate.LockOptions;
|
import org.hibernate.LockOptions;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|
||||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||||
import org.hibernate.loader.ast.spi.SingleIdEntityLoader;
|
import org.hibernate.loader.ast.spi.SingleIdEntityLoader;
|
||||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||||
import org.hibernate.query.named.NamedQueryMemento;
|
import org.hibernate.query.named.NamedQueryMemento;
|
||||||
import org.hibernate.query.named.NamedObjectRepository;
|
|
||||||
import org.hibernate.query.spi.QueryImplementor;
|
import org.hibernate.query.spi.QueryImplementor;
|
||||||
import org.hibernate.query.sql.spi.NamedNativeQueryMemento;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of SingleIdEntityLoader for cases where the application has
|
* Implementation of SingleIdEntityLoader for cases where the application has
|
||||||
|
@ -29,27 +26,9 @@ public class SingleIdEntityLoaderProvidedQueryImpl<T> implements SingleIdEntityL
|
||||||
|
|
||||||
public SingleIdEntityLoaderProvidedQueryImpl(
|
public SingleIdEntityLoaderProvidedQueryImpl(
|
||||||
EntityMappingType entityDescriptor,
|
EntityMappingType entityDescriptor,
|
||||||
String loadQueryName,
|
NamedQueryMemento namedQueryMemento) {
|
||||||
SessionFactoryImplementor sessionFactory) {
|
|
||||||
this.entityDescriptor = entityDescriptor;
|
this.entityDescriptor = entityDescriptor;
|
||||||
|
this.namedQueryMemento = namedQueryMemento;
|
||||||
this.namedQueryMemento = resolveNamedQuery( loadQueryName, sessionFactory );
|
|
||||||
if ( namedQueryMemento == null ) {
|
|
||||||
throw new IllegalArgumentException( "Could not resolve named load-query [" + entityDescriptor.getEntityName() + "] : " + loadQueryName );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static NamedQueryMemento resolveNamedQuery(
|
|
||||||
String queryName,
|
|
||||||
SessionFactoryImplementor sf) {
|
|
||||||
final NamedObjectRepository namedObjectRepository = sf.getQueryEngine().getNamedObjectRepository();
|
|
||||||
|
|
||||||
final NamedNativeQueryMemento nativeQueryMemento = namedObjectRepository.getNativeQueryMemento( queryName );
|
|
||||||
if ( nativeQueryMemento != null ) {
|
|
||||||
return nativeQueryMemento;
|
|
||||||
}
|
|
||||||
|
|
||||||
return namedObjectRepository.getHqlQueryMemento( queryName );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -65,7 +44,7 @@ public class SingleIdEntityLoaderProvidedQueryImpl<T> implements SingleIdEntityL
|
||||||
entityDescriptor.getMappedJavaTypeDescriptor().getJavaTypeClass()
|
entityDescriptor.getMappedJavaTypeDescriptor().getJavaTypeClass()
|
||||||
);
|
);
|
||||||
|
|
||||||
query.setParameter( 0, pkValue );
|
query.setParameter( 1, pkValue );
|
||||||
|
|
||||||
return query.uniqueResult();
|
return query.uniqueResult();
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,6 +135,7 @@ import org.hibernate.mapping.BasicValue;
|
||||||
import org.hibernate.mapping.Column;
|
import org.hibernate.mapping.Column;
|
||||||
import org.hibernate.mapping.Component;
|
import org.hibernate.mapping.Component;
|
||||||
import org.hibernate.mapping.DependantValue;
|
import org.hibernate.mapping.DependantValue;
|
||||||
|
import org.hibernate.mapping.Formula;
|
||||||
import org.hibernate.mapping.IndexedConsumer;
|
import org.hibernate.mapping.IndexedConsumer;
|
||||||
import org.hibernate.mapping.PersistentClass;
|
import org.hibernate.mapping.PersistentClass;
|
||||||
import org.hibernate.mapping.Property;
|
import org.hibernate.mapping.Property;
|
||||||
|
@ -188,6 +189,8 @@ import org.hibernate.property.access.spi.PropertyAccess;
|
||||||
import org.hibernate.property.access.spi.Setter;
|
import org.hibernate.property.access.spi.Setter;
|
||||||
import org.hibernate.query.ComparisonOperator;
|
import org.hibernate.query.ComparisonOperator;
|
||||||
import org.hibernate.query.NavigablePath;
|
import org.hibernate.query.NavigablePath;
|
||||||
|
import org.hibernate.query.named.NamedQueryMemento;
|
||||||
|
import org.hibernate.query.sql.internal.SQLQueryParser;
|
||||||
import org.hibernate.query.sqm.mutation.internal.SqmMutationStrategyHelper;
|
import org.hibernate.query.sqm.mutation.internal.SqmMutationStrategyHelper;
|
||||||
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
|
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
|
||||||
import org.hibernate.sql.Alias;
|
import org.hibernate.sql.Alias;
|
||||||
|
@ -748,10 +751,15 @@ public abstract class AbstractEntityPersister
|
||||||
rowIdName = bootDescriptor.getRootTable().getRowId();
|
rowIdName = bootDescriptor.getRootTable().getRowId();
|
||||||
|
|
||||||
if ( bootDescriptor.getLoaderName() != null ) {
|
if ( bootDescriptor.getLoaderName() != null ) {
|
||||||
|
// We must resolve the named query on-demand through the boot model because it isn't initialized yet
|
||||||
|
final NamedQueryMemento namedQueryMemento = factory.getQueryEngine().getNamedObjectRepository()
|
||||||
|
.resolve( factory, creationContext.getBootModel(), bootDescriptor.getLoaderName() );
|
||||||
|
if ( namedQueryMemento == null ) {
|
||||||
|
throw new IllegalArgumentException( "Could not resolve named load-query [" + getEntityName() + "] : " + bootDescriptor.getLoaderName() );
|
||||||
|
}
|
||||||
singleIdEntityLoader = new SingleIdEntityLoaderProvidedQueryImpl(
|
singleIdEntityLoader = new SingleIdEntityLoaderProvidedQueryImpl(
|
||||||
this,
|
this,
|
||||||
bootDescriptor.getLoaderName(),
|
namedQueryMemento
|
||||||
factory
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if ( batchSize > 1 ) {
|
else if ( batchSize > 1 ) {
|
||||||
|
@ -849,8 +857,7 @@ public abstract class AbstractEntityPersister
|
||||||
colAliases[k] = thing.getAlias( dialect, prop.getValue().getTable() );
|
colAliases[k] = thing.getAlias( dialect, prop.getValue().getTable() );
|
||||||
if ( thing.isFormula() ) {
|
if ( thing.isFormula() ) {
|
||||||
foundFormula = true;
|
foundFormula = true;
|
||||||
// ( (Formula) thing ).setFormula( substituteBrackets( ( (Formula) thing ).getFormula() ) );
|
( (Formula) thing ).setFormula( substituteBrackets( ( (Formula) thing ).getFormula() ) );
|
||||||
// TODO: uncomment the above statement when this#substituteBrackets(String) is implemented
|
|
||||||
formulaTemplates[k] = thing.getTemplate( dialect, factory.getQueryEngine().getSqmFunctionRegistry() );
|
formulaTemplates[k] = thing.getTemplate( dialect, factory.getQueryEngine().getSqmFunctionRegistry() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -4562,7 +4569,7 @@ public abstract class AbstractEntityPersister
|
||||||
}
|
}
|
||||||
|
|
||||||
private String substituteBrackets(String sql) {
|
private String substituteBrackets(String sql) {
|
||||||
throw new NotYetImplementedFor6Exception( getClass() );
|
return new SQLQueryParser( sql, null, getFactory() ).process();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void postInstantiate() throws MappingException {
|
public final void postInstantiate() throws MappingException {
|
||||||
|
|
|
@ -11,6 +11,9 @@ import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
|
import org.hibernate.boot.query.NamedHqlQueryDefinition;
|
||||||
|
import org.hibernate.boot.query.NamedNativeQueryDefinition;
|
||||||
|
import org.hibernate.boot.query.NamedProcedureCallDefinition;
|
||||||
import org.hibernate.boot.spi.BootstrapContext;
|
import org.hibernate.boot.spi.BootstrapContext;
|
||||||
import org.hibernate.boot.spi.MetadataImplementor;
|
import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
|
@ -18,6 +21,7 @@ import org.hibernate.procedure.spi.NamedCallableQueryMemento;
|
||||||
import org.hibernate.query.hql.HqlTranslator;
|
import org.hibernate.query.hql.HqlTranslator;
|
||||||
import org.hibernate.query.hql.spi.NamedHqlQueryMemento;
|
import org.hibernate.query.hql.spi.NamedHqlQueryMemento;
|
||||||
import org.hibernate.query.named.NamedObjectRepository;
|
import org.hibernate.query.named.NamedObjectRepository;
|
||||||
|
import org.hibernate.query.named.NamedQueryMemento;
|
||||||
import org.hibernate.query.named.NamedResultSetMappingMemento;
|
import org.hibernate.query.named.NamedResultSetMappingMemento;
|
||||||
import org.hibernate.query.spi.QueryEngine;
|
import org.hibernate.query.spi.QueryEngine;
|
||||||
import org.hibernate.query.spi.QueryInterpretationCache;
|
import org.hibernate.query.spi.QueryInterpretationCache;
|
||||||
|
@ -127,6 +131,44 @@ public class NamedObjectRepositoryImpl implements NamedObjectRepository {
|
||||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
// Prepare repository for use
|
// Prepare repository for use
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NamedQueryMemento resolve(
|
||||||
|
SessionFactoryImplementor sessionFactory,
|
||||||
|
MetadataImplementor bootMetamodel,
|
||||||
|
String registrationName) {
|
||||||
|
NamedQueryMemento namedQuery = hqlMementoMap.get( registrationName );
|
||||||
|
if ( namedQuery != null ) {
|
||||||
|
return namedQuery;
|
||||||
|
}
|
||||||
|
namedQuery = sqlMementoMap.get( registrationName );
|
||||||
|
if ( namedQuery != null ) {
|
||||||
|
return namedQuery;
|
||||||
|
}
|
||||||
|
namedQuery = callableMementoMap.get( registrationName );
|
||||||
|
if ( namedQuery != null ) {
|
||||||
|
return namedQuery;
|
||||||
|
}
|
||||||
|
final NamedHqlQueryDefinition namedHqlQueryDefinition = bootMetamodel.getNamedHqlQueryMapping( registrationName );
|
||||||
|
if ( namedHqlQueryDefinition != null ) {
|
||||||
|
final NamedHqlQueryMemento resolved = namedHqlQueryDefinition.resolve( sessionFactory );
|
||||||
|
hqlMementoMap.put( namedHqlQueryDefinition.getRegistrationName(), resolved );
|
||||||
|
return resolved;
|
||||||
|
}
|
||||||
|
final NamedNativeQueryDefinition namedNativeQueryDefinition = bootMetamodel.getNamedNativeQueryMapping( registrationName );
|
||||||
|
if ( namedNativeQueryDefinition != null ) {
|
||||||
|
final NamedNativeQueryMemento resolved = namedNativeQueryDefinition.resolve( sessionFactory );
|
||||||
|
sqlMementoMap.put( namedNativeQueryDefinition.getRegistrationName(), resolved );
|
||||||
|
return resolved;
|
||||||
|
}
|
||||||
|
final NamedProcedureCallDefinition namedCallableQueryDefinition = bootMetamodel.getNamedProcedureCallMapping( registrationName );
|
||||||
|
if ( namedCallableQueryDefinition != null ) {
|
||||||
|
final NamedCallableQueryMemento resolved = namedCallableQueryDefinition.resolve( sessionFactory );
|
||||||
|
callableMementoMap.put( namedCallableQueryDefinition.getRegistrationName(), resolved );
|
||||||
|
return resolved;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prepare(
|
public void prepare(
|
||||||
SessionFactoryImplementor sessionFactory,
|
SessionFactoryImplementor sessionFactory,
|
||||||
|
@ -184,10 +226,11 @@ public class NamedObjectRepositoryImpl implements NamedObjectRepository {
|
||||||
for ( NamedHqlQueryMemento hqlMemento : hqlMementoMap.values() ) {
|
for ( NamedHqlQueryMemento hqlMemento : hqlMementoMap.values() ) {
|
||||||
try {
|
try {
|
||||||
log.debugf( "Checking named HQL query: %s", hqlMemento.getRegistrationName() );
|
log.debugf( "Checking named HQL query: %s", hqlMemento.getRegistrationName() );
|
||||||
hqlMemento.validate( queryEngine );
|
String queryString = hqlMemento.getHqlString();
|
||||||
|
interpretationCache.resolveHqlInterpretation(
|
||||||
// todo (6.0) : need to cache these; however atm that requires producing a SqmQueryImpl
|
queryString,
|
||||||
// queryEngine.getQueryInterpretationCache().getHQLQueryPlan( hqlMemento.getQueryString(), false, Collections.EMPTY_MAP );
|
s -> queryEngine.getHqlTranslator().translate( queryString )
|
||||||
|
);
|
||||||
}
|
}
|
||||||
catch ( HibernateException e ) {
|
catch ( HibernateException e ) {
|
||||||
errors.put( hqlMemento.getRegistrationName(), e );
|
errors.put( hqlMemento.getRegistrationName(), e );
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.query.internal;
|
package org.hibernate.query.internal;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
@ -17,15 +18,18 @@ import org.hibernate.query.spi.SelectQueryPlan;
|
||||||
import org.hibernate.query.sql.spi.ParameterInterpretation;
|
import org.hibernate.query.sql.spi.ParameterInterpretation;
|
||||||
import org.hibernate.query.sqm.internal.DomainParameterXref;
|
import org.hibernate.query.sqm.internal.DomainParameterXref;
|
||||||
import org.hibernate.query.sqm.tree.SqmStatement;
|
import org.hibernate.query.sqm.tree.SqmStatement;
|
||||||
|
import org.hibernate.stat.spi.StatisticsImplementor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class QueryInterpretationCacheDisabledImpl implements QueryInterpretationCache {
|
public class QueryInterpretationCacheDisabledImpl implements QueryInterpretationCache {
|
||||||
/**
|
|
||||||
* Singleton access
|
private final Supplier<StatisticsImplementor> statisticsSupplier;
|
||||||
*/
|
|
||||||
public static final QueryInterpretationCacheDisabledImpl INSTANCE = new QueryInterpretationCacheDisabledImpl();
|
public QueryInterpretationCacheDisabledImpl(Supplier<StatisticsImplementor> statisticsSupplier) {
|
||||||
|
this.statisticsSupplier = statisticsSupplier;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNumberOfCachedHqlInterpretations() {
|
public int getNumberOfCachedHqlInterpretations() {
|
||||||
|
@ -53,6 +57,9 @@ public class QueryInterpretationCacheDisabledImpl implements QueryInterpretation
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HqlInterpretation resolveHqlInterpretation(String queryString, Function<String, SqmStatement<?>> creator) {
|
public HqlInterpretation resolveHqlInterpretation(String queryString, Function<String, SqmStatement<?>> creator) {
|
||||||
|
StatisticsImplementor statistics = statisticsSupplier.get();
|
||||||
|
final boolean stats = statistics.isStatisticsEnabled();
|
||||||
|
final long startTime = ( stats ) ? System.nanoTime() : 0L;
|
||||||
final SqmStatement<?> sqmStatement = creator.apply( queryString );
|
final SqmStatement<?> sqmStatement = creator.apply( queryString );
|
||||||
|
|
||||||
final DomainParameterXref domainParameterXref;
|
final DomainParameterXref domainParameterXref;
|
||||||
|
@ -66,6 +73,12 @@ public class QueryInterpretationCacheDisabledImpl implements QueryInterpretation
|
||||||
parameterMetadata = new ParameterMetadataImpl( domainParameterXref.getQueryParameters() );
|
parameterMetadata = new ParameterMetadataImpl( domainParameterXref.getQueryParameters() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( stats ) {
|
||||||
|
final long endTime = System.nanoTime();
|
||||||
|
final long microseconds = TimeUnit.MICROSECONDS.convert( endTime - startTime, TimeUnit.NANOSECONDS );
|
||||||
|
statistics.queryCompiled( queryString, microseconds );
|
||||||
|
}
|
||||||
|
|
||||||
return new HqlInterpretation() {
|
return new HqlInterpretation() {
|
||||||
@Override
|
@Override
|
||||||
public SqmStatement getSqmStatement() {
|
public SqmStatement getSqmStatement() {
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.query.internal;
|
package org.hibernate.query.internal;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
@ -21,6 +22,7 @@ import org.hibernate.query.spi.SimpleHqlInterpretationImpl;
|
||||||
import org.hibernate.query.sql.spi.ParameterInterpretation;
|
import org.hibernate.query.sql.spi.ParameterInterpretation;
|
||||||
import org.hibernate.query.sqm.internal.DomainParameterXref;
|
import org.hibernate.query.sqm.internal.DomainParameterXref;
|
||||||
import org.hibernate.query.sqm.tree.SqmStatement;
|
import org.hibernate.query.sqm.tree.SqmStatement;
|
||||||
|
import org.hibernate.stat.spi.StatisticsImplementor;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
|
@ -52,13 +54,15 @@ public class QueryInterpretationCacheStandardImpl implements QueryInterpretation
|
||||||
|
|
||||||
private final BoundedConcurrentHashMap<String, HqlInterpretation> hqlInterpretationCache;
|
private final BoundedConcurrentHashMap<String, HqlInterpretation> hqlInterpretationCache;
|
||||||
private final BoundedConcurrentHashMap<String, ParameterInterpretation> nativeQueryParamCache;
|
private final BoundedConcurrentHashMap<String, ParameterInterpretation> nativeQueryParamCache;
|
||||||
|
private final Supplier<StatisticsImplementor> statisticsSupplier;
|
||||||
|
|
||||||
public QueryInterpretationCacheStandardImpl(int maxQueryPlanCount) {
|
public QueryInterpretationCacheStandardImpl(int maxQueryPlanCount, Supplier<StatisticsImplementor> statisticsSupplier) {
|
||||||
log.debugf( "Starting QueryPlanCache(%s)", maxQueryPlanCount );
|
log.debugf( "Starting QueryPlanCache(%s)", maxQueryPlanCount );
|
||||||
|
|
||||||
queryPlanCache = new BoundedConcurrentHashMap<>( maxQueryPlanCount, 20, BoundedConcurrentHashMap.Eviction.LIRS );
|
this.queryPlanCache = new BoundedConcurrentHashMap<>( maxQueryPlanCount, 20, BoundedConcurrentHashMap.Eviction.LIRS );
|
||||||
hqlInterpretationCache = new BoundedConcurrentHashMap<>( maxQueryPlanCount, 20, BoundedConcurrentHashMap.Eviction.LIRS );
|
this.hqlInterpretationCache = new BoundedConcurrentHashMap<>( maxQueryPlanCount, 20, BoundedConcurrentHashMap.Eviction.LIRS );
|
||||||
nativeQueryParamCache = new BoundedConcurrentHashMap<>( maxQueryPlanCount, 20, BoundedConcurrentHashMap.Eviction.LIRS );
|
this.nativeQueryParamCache = new BoundedConcurrentHashMap<>( maxQueryPlanCount, 20, BoundedConcurrentHashMap.Eviction.LIRS );
|
||||||
|
this.statisticsSupplier = statisticsSupplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -103,9 +107,14 @@ public class QueryInterpretationCacheStandardImpl implements QueryInterpretation
|
||||||
String queryString,
|
String queryString,
|
||||||
Function<String, SqmStatement<?>> creator) {
|
Function<String, SqmStatement<?>> creator) {
|
||||||
log.tracef( "QueryPlan#resolveHqlInterpretation( `%s` )", queryString );
|
log.tracef( "QueryPlan#resolveHqlInterpretation( `%s` )", queryString );
|
||||||
|
final StatisticsImplementor statistics = statisticsSupplier.get();
|
||||||
|
final boolean stats = statistics.isStatisticsEnabled();
|
||||||
|
final long startTime = ( stats ) ? System.nanoTime() : 0L;
|
||||||
final HqlInterpretation cached = hqlInterpretationCache.get( queryString );
|
final HqlInterpretation cached = hqlInterpretationCache.get( queryString );
|
||||||
if ( cached != null ) {
|
if ( cached != null ) {
|
||||||
|
if ( stats ) {
|
||||||
|
statistics.queryPlanCacheHit( queryString );
|
||||||
|
}
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,6 +138,12 @@ public class QueryInterpretationCacheStandardImpl implements QueryInterpretation
|
||||||
parameterMetadata,
|
parameterMetadata,
|
||||||
domainParameterXref);
|
domainParameterXref);
|
||||||
hqlInterpretationCache.put( queryString, interpretation );
|
hqlInterpretationCache.put( queryString, interpretation );
|
||||||
|
|
||||||
|
if ( stats ) {
|
||||||
|
final long endTime = System.nanoTime();
|
||||||
|
final long microseconds = TimeUnit.MICROSECONDS.convert( endTime - startTime, TimeUnit.NANOSECONDS );
|
||||||
|
statistics.queryCompiled( queryString, microseconds );
|
||||||
|
}
|
||||||
return interpretation;
|
return interpretation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,6 +170,8 @@ public class QueryInterpretationCacheStandardImpl implements QueryInterpretation
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
// todo (6.0) : clear maps/caches and LOG
|
// todo (6.0) : clear maps/caches and LOG
|
||||||
|
hqlInterpretationCache.clear();
|
||||||
|
nativeQueryParamCache.clear();
|
||||||
queryPlanCache.clear();
|
queryPlanCache.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,14 @@ public interface NamedObjectRepository {
|
||||||
*/
|
*/
|
||||||
Map<String, HibernateException> checkNamedQueries(QueryEngine queryPlanCache);
|
Map<String, HibernateException> checkNamedQueries(QueryEngine queryPlanCache);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve the named query with the given name.
|
||||||
|
*/
|
||||||
|
NamedQueryMemento resolve(
|
||||||
|
SessionFactoryImplementor sessionFactory,
|
||||||
|
MetadataImplementor bootMetamodel,
|
||||||
|
String registrationName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare for runtime use
|
* Prepare for runtime use
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.query.spi;
|
package org.hibernate.query.spi;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
|
||||||
import org.hibernate.Incubating;
|
import org.hibernate.Incubating;
|
||||||
import org.hibernate.boot.spi.BootstrapContext;
|
import org.hibernate.boot.spi.BootstrapContext;
|
||||||
import org.hibernate.boot.spi.MetadataImplementor;
|
import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
|
@ -18,7 +17,6 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.internal.CoreLogging;
|
import org.hibernate.internal.CoreLogging;
|
||||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||||
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
||||||
import org.hibernate.query.QueryLogging;
|
|
||||||
import org.hibernate.query.criteria.ValueHandlingMode;
|
import org.hibernate.query.criteria.ValueHandlingMode;
|
||||||
import org.hibernate.query.hql.HqlTranslator;
|
import org.hibernate.query.hql.HqlTranslator;
|
||||||
import org.hibernate.query.hql.internal.StandardHqlTranslator;
|
import org.hibernate.query.hql.internal.StandardHqlTranslator;
|
||||||
|
@ -34,6 +32,7 @@ import org.hibernate.query.sqm.spi.SqmCreationContext;
|
||||||
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
|
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
|
||||||
import org.hibernate.query.sqm.sql.StandardSqmTranslatorFactory;
|
import org.hibernate.query.sqm.sql.StandardSqmTranslatorFactory;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
|
import org.hibernate.stat.spi.StatisticsImplementor;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
@ -75,7 +74,7 @@ public class QueryEngine {
|
||||||
hqlTranslator,
|
hqlTranslator,
|
||||||
sqmTranslatorFactory,
|
sqmTranslatorFactory,
|
||||||
sessionFactory.getServiceRegistry().getService( NativeQueryInterpreter.class ),
|
sessionFactory.getServiceRegistry().getService( NativeQueryInterpreter.class ),
|
||||||
buildInterpretationCache( sessionFactory.getProperties() ),
|
buildInterpretationCache( sessionFactory::getStatistics, sessionFactory.getProperties() ),
|
||||||
dialect,
|
dialect,
|
||||||
queryEngineOptions.getCustomSqmFunctionRegistry(),
|
queryEngineOptions.getCustomSqmFunctionRegistry(),
|
||||||
sessionFactory.getServiceRegistry()
|
sessionFactory.getServiceRegistry()
|
||||||
|
@ -196,6 +195,7 @@ public class QueryEngine {
|
||||||
);
|
);
|
||||||
|
|
||||||
this.interpretationCache = buildInterpretationCache(
|
this.interpretationCache = buildInterpretationCache(
|
||||||
|
() -> serviceRegistry.getService( StatisticsImplementor.class ),
|
||||||
serviceRegistry.getService( ConfigurationService.class ).getSettings()
|
serviceRegistry.getService( ConfigurationService.class ).getSettings()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -275,7 +275,7 @@ public class QueryEngine {
|
||||||
return new StandardSqmTranslatorFactory();
|
return new StandardSqmTranslatorFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static QueryInterpretationCache buildInterpretationCache(Map properties) {
|
private static QueryInterpretationCache buildInterpretationCache(Supplier<StatisticsImplementor> statisticsSupplier, Map properties) {
|
||||||
final boolean explicitUseCache = ConfigurationHelper.getBoolean(
|
final boolean explicitUseCache = ConfigurationHelper.getBoolean(
|
||||||
AvailableSettings.QUERY_PLAN_CACHE_ENABLED,
|
AvailableSettings.QUERY_PLAN_CACHE_ENABLED,
|
||||||
properties,
|
properties,
|
||||||
|
@ -293,11 +293,11 @@ public class QueryEngine {
|
||||||
? explicitMaxPlanSize
|
? explicitMaxPlanSize
|
||||||
: QueryInterpretationCacheStandardImpl.DEFAULT_QUERY_PLAN_MAX_COUNT;
|
: QueryInterpretationCacheStandardImpl.DEFAULT_QUERY_PLAN_MAX_COUNT;
|
||||||
|
|
||||||
return new QueryInterpretationCacheStandardImpl( size );
|
return new QueryInterpretationCacheStandardImpl( size, statisticsSupplier );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// disabled
|
// disabled
|
||||||
return QueryInterpretationCacheDisabledImpl.INSTANCE;
|
return new QueryInterpretationCacheDisabledImpl( statisticsSupplier );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,22 +306,6 @@ public class QueryEngine {
|
||||||
MetadataImplementor bootMetamodel,
|
MetadataImplementor bootMetamodel,
|
||||||
BootstrapContext bootstrapContext) {
|
BootstrapContext bootstrapContext) {
|
||||||
namedObjectRepository.prepare( sessionFactory, bootMetamodel, bootstrapContext );
|
namedObjectRepository.prepare( sessionFactory, bootMetamodel, bootstrapContext );
|
||||||
|
|
||||||
//checking for named queries
|
|
||||||
if ( sessionFactory.getSessionFactoryOptions().isNamedQueryStartupCheckingEnabled() ) {
|
|
||||||
final Map<String, HibernateException> errors = namedObjectRepository.checkNamedQueries( this );
|
|
||||||
|
|
||||||
if ( !errors.isEmpty() ) {
|
|
||||||
StringBuilder failingQueries = new StringBuilder( "Errors in named queries: " );
|
|
||||||
String sep = "";
|
|
||||||
for ( Map.Entry<String, HibernateException> entry : errors.entrySet() ) {
|
|
||||||
QueryLogging.QUERY_MESSAGE_LOGGER.namedQueryError( entry.getKey(), entry.getValue() );
|
|
||||||
failingQueries.append( sep ).append( entry.getKey() );
|
|
||||||
sep = ", ";
|
|
||||||
}
|
|
||||||
throw new HibernateException( failingQueries.toString() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public NamedObjectRepository getNamedObjectRepository() {
|
public NamedObjectRepository getNamedObjectRepository() {
|
||||||
|
|
|
@ -289,12 +289,13 @@ public class NativeQueryImpl<R>
|
||||||
sqlString,
|
sqlString,
|
||||||
s -> {
|
s -> {
|
||||||
final ParameterRecognizerImpl parameterRecognizer = new ParameterRecognizerImpl( session.getFactory() );
|
final ParameterRecognizerImpl parameterRecognizer = new ParameterRecognizerImpl( session.getFactory() );
|
||||||
|
final String sql = new SQLQueryParser( sqlString, null, session.getFactory() ).process();
|
||||||
|
|
||||||
session.getFactory().getServiceRegistry()
|
session.getFactory().getServiceRegistry()
|
||||||
.getService( NativeQueryInterpreter.class )
|
.getService( NativeQueryInterpreter.class )
|
||||||
.recognizeParameters( sqlString, parameterRecognizer );
|
.recognizeParameters( sql, parameterRecognizer );
|
||||||
|
|
||||||
return new ParameterInterpretationImpl( sqlString, parameterRecognizer );
|
return new ParameterInterpretationImpl( sql, parameterRecognizer );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,261 @@
|
||||||
|
/*
|
||||||
|
* 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.query.sql.internal;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.hibernate.QueryException;
|
||||||
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
|
import org.hibernate.persister.collection.SQLLoadableCollection;
|
||||||
|
import org.hibernate.persister.entity.SQLLoadable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gavin King
|
||||||
|
* @author Max Andersen
|
||||||
|
* @author Steve Ebersole
|
||||||
|
* @author Paul Benedict
|
||||||
|
*/
|
||||||
|
public class SQLQueryParser {
|
||||||
|
private static final Pattern PREPARED_STATEMENT_PATTERN = Pattern.compile( "^\\{.*?\\}$" );
|
||||||
|
private static final String HIBERNATE_PLACEHOLDER_PREFIX = "h-";
|
||||||
|
private static final String DOMAIN_PLACEHOLDER = "h-domain";
|
||||||
|
private static final String CATALOG_PLACEHOLDER = "h-catalog";
|
||||||
|
private static final String SCHEMA_PLACEHOLDER = "h-schema";
|
||||||
|
|
||||||
|
private final SessionFactoryImplementor factory;
|
||||||
|
private final String originalQueryString;
|
||||||
|
private final ParserContext context;
|
||||||
|
|
||||||
|
private long aliasesFound;
|
||||||
|
|
||||||
|
interface ParserContext {
|
||||||
|
boolean isEntityAlias(String aliasName);
|
||||||
|
SQLLoadable getEntityPersisterByAlias(String alias);
|
||||||
|
String getEntitySuffixByAlias(String alias);
|
||||||
|
boolean isCollectionAlias(String aliasName);
|
||||||
|
SQLLoadableCollection getCollectionPersisterByAlias(String alias);
|
||||||
|
String getCollectionSuffixByAlias(String alias);
|
||||||
|
Map getPropertyResultsMapByAlias(String alias);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SQLQueryParser(String queryString, ParserContext context, SessionFactoryImplementor factory) {
|
||||||
|
this.originalQueryString = queryString;
|
||||||
|
this.context = context;
|
||||||
|
this.factory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean queryHasAliases() {
|
||||||
|
return aliasesFound>0;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getOriginalQueryString() {
|
||||||
|
return originalQueryString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String process() {
|
||||||
|
return substituteBrackets( originalQueryString );
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: should "record" how many properties we have referred to - and if we
|
||||||
|
// don't get them all we throw an exception! Way better than trial and error ;)
|
||||||
|
protected String substituteBrackets(String sqlQuery) throws QueryException {
|
||||||
|
|
||||||
|
if ( PREPARED_STATEMENT_PATTERN.matcher( sqlQuery.trim() ).matches() ) {
|
||||||
|
return sqlQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder result = new StringBuilder( sqlQuery.length() + 20 );
|
||||||
|
int left, right;
|
||||||
|
|
||||||
|
// replace {....} with corresponding column aliases
|
||||||
|
for ( int curr = 0; curr < sqlQuery.length(); curr = right + 1 ) {
|
||||||
|
if ( ( left = sqlQuery.indexOf( '{', curr ) ) < 0 ) {
|
||||||
|
// No additional open braces found in the string, append the
|
||||||
|
// rest of the string in its entirety and quit this loop
|
||||||
|
result.append( sqlQuery.substring( curr ) );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// append everything up until the next encountered open brace
|
||||||
|
result.append( sqlQuery.substring( curr, left ) );
|
||||||
|
|
||||||
|
if ( ( right = sqlQuery.indexOf( '}', left + 1 ) ) < 0 ) {
|
||||||
|
throw new QueryException( "Unmatched braces for alias path", sqlQuery );
|
||||||
|
}
|
||||||
|
|
||||||
|
final String aliasPath = sqlQuery.substring( left + 1, right );
|
||||||
|
boolean isPlaceholder = aliasPath.startsWith( HIBERNATE_PLACEHOLDER_PREFIX );
|
||||||
|
|
||||||
|
if ( isPlaceholder ) {
|
||||||
|
// Domain replacement
|
||||||
|
if ( DOMAIN_PLACEHOLDER.equals( aliasPath ) ) {
|
||||||
|
final String catalogName = factory.getSettings().getDefaultCatalogName();
|
||||||
|
if ( catalogName != null ) {
|
||||||
|
result.append( catalogName );
|
||||||
|
result.append( "." );
|
||||||
|
}
|
||||||
|
final String schemaName = factory.getSettings().getDefaultSchemaName();
|
||||||
|
if ( schemaName != null ) {
|
||||||
|
result.append( schemaName );
|
||||||
|
result.append( "." );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Schema replacement
|
||||||
|
else if ( SCHEMA_PLACEHOLDER.equals( aliasPath ) ) {
|
||||||
|
final String schemaName = factory.getSettings().getDefaultSchemaName();
|
||||||
|
if ( schemaName != null ) {
|
||||||
|
result.append(schemaName);
|
||||||
|
result.append(".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Catalog replacement
|
||||||
|
else if ( CATALOG_PLACEHOLDER.equals( aliasPath ) ) {
|
||||||
|
final String catalogName = factory.getSettings().getDefaultCatalogName();
|
||||||
|
if ( catalogName != null ) {
|
||||||
|
result.append( catalogName );
|
||||||
|
result.append( "." );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new QueryException( "Unknown placeholder ", aliasPath );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (context != null) {
|
||||||
|
int firstDot = aliasPath.indexOf( '.' );
|
||||||
|
if ( firstDot == -1 ) {
|
||||||
|
if ( context.isEntityAlias( aliasPath ) ) {
|
||||||
|
// it is a simple table alias {foo}
|
||||||
|
result.append( aliasPath );
|
||||||
|
aliasesFound++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// passing through anything we do not know : to support jdbc escape sequences HB-898
|
||||||
|
result.append( '{' ).append(aliasPath).append( '}' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
final String aliasName = aliasPath.substring( 0, firstDot );
|
||||||
|
if ( context.isCollectionAlias( aliasName ) ) {
|
||||||
|
// The current alias is referencing the collection to be eagerly fetched
|
||||||
|
String propertyName = aliasPath.substring( firstDot + 1 );
|
||||||
|
result.append( resolveCollectionProperties( aliasName, propertyName ) );
|
||||||
|
aliasesFound++;
|
||||||
|
}
|
||||||
|
else if ( context.isEntityAlias( aliasName ) ) {
|
||||||
|
// it is a property reference {foo.bar}
|
||||||
|
String propertyName = aliasPath.substring( firstDot + 1 );
|
||||||
|
result.append( resolveProperties( aliasName, propertyName ) );
|
||||||
|
aliasesFound++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// passing through anything we do not know : to support jdbc escape sequences HB-898
|
||||||
|
result.append( '{' ).append(aliasPath).append( '}' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result.append( '{' ).append(aliasPath).append( '}' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Possibly handle :something parameters for the query ?
|
||||||
|
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String resolveCollectionProperties(
|
||||||
|
String aliasName,
|
||||||
|
String propertyName) {
|
||||||
|
|
||||||
|
Map fieldResults = context.getPropertyResultsMapByAlias( aliasName );
|
||||||
|
SQLLoadableCollection collectionPersister = context.getCollectionPersisterByAlias( aliasName );
|
||||||
|
String collectionSuffix = context.getCollectionSuffixByAlias( aliasName );
|
||||||
|
|
||||||
|
if ( "*".equals( propertyName ) ) {
|
||||||
|
if( !fieldResults.isEmpty() ) {
|
||||||
|
throw new QueryException("Using return-propertys together with * syntax is not supported.");
|
||||||
|
}
|
||||||
|
|
||||||
|
String selectFragment = collectionPersister.selectFragment( aliasName, collectionSuffix );
|
||||||
|
aliasesFound++;
|
||||||
|
return selectFragment
|
||||||
|
+ ", "
|
||||||
|
+ resolveProperties( aliasName, propertyName );
|
||||||
|
}
|
||||||
|
else if ( "element.*".equals( propertyName ) ) {
|
||||||
|
return resolveProperties( aliasName, "*" );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
String[] columnAliases;
|
||||||
|
|
||||||
|
// Let return-properties override whatever the persister has for aliases.
|
||||||
|
columnAliases = ( String[] ) fieldResults.get(propertyName);
|
||||||
|
if ( columnAliases==null ) {
|
||||||
|
columnAliases = collectionPersister.getCollectionPropertyColumnAliases( propertyName, collectionSuffix );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( columnAliases == null || columnAliases.length == 0 ) {
|
||||||
|
throw new QueryException(
|
||||||
|
"No column name found for property [" + propertyName + "] for alias [" + aliasName + "]",
|
||||||
|
originalQueryString
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ( columnAliases.length != 1 ) {
|
||||||
|
// TODO: better error message since we actually support composites if names are explicitly listed.
|
||||||
|
throw new QueryException(
|
||||||
|
"SQL queries only support properties mapped to a single column - property [" +
|
||||||
|
propertyName + "] is mapped to " + columnAliases.length + " columns.",
|
||||||
|
originalQueryString
|
||||||
|
);
|
||||||
|
}
|
||||||
|
aliasesFound++;
|
||||||
|
return columnAliases[0];
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private String resolveProperties(String aliasName, String propertyName) {
|
||||||
|
Map fieldResults = context.getPropertyResultsMapByAlias( aliasName );
|
||||||
|
SQLLoadable persister = context.getEntityPersisterByAlias( aliasName );
|
||||||
|
String suffix = context.getEntitySuffixByAlias( aliasName );
|
||||||
|
|
||||||
|
if ( "*".equals( propertyName ) ) {
|
||||||
|
if( !fieldResults.isEmpty() ) {
|
||||||
|
throw new QueryException("Using return-propertys together with * syntax is not supported.");
|
||||||
|
}
|
||||||
|
aliasesFound++;
|
||||||
|
return persister.selectFragment( aliasName, suffix ) ;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
String[] columnAliases;
|
||||||
|
|
||||||
|
// Let return-propertiess override whatever the persister has for aliases.
|
||||||
|
columnAliases = (String[]) fieldResults.get( propertyName );
|
||||||
|
if ( columnAliases == null ) {
|
||||||
|
columnAliases = persister.getSubclassPropertyColumnAliases( propertyName, suffix );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( columnAliases == null || columnAliases.length == 0 ) {
|
||||||
|
throw new QueryException(
|
||||||
|
"No column name found for property [" + propertyName + "] for alias [" + aliasName + "]",
|
||||||
|
originalQueryString
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ( columnAliases.length != 1 ) {
|
||||||
|
// TODO: better error message since we actually support composites if names are explicitly listed.
|
||||||
|
throw new QueryException(
|
||||||
|
"SQL queries only support properties mapped to a single column - property [" + propertyName + "] is mapped to " + columnAliases.length + " columns.",
|
||||||
|
originalQueryString
|
||||||
|
);
|
||||||
|
}
|
||||||
|
aliasesFound++;
|
||||||
|
return columnAliases[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -45,6 +45,7 @@ import org.hibernate.query.spi.HqlInterpretation;
|
||||||
import org.hibernate.query.spi.MutableQueryOptions;
|
import org.hibernate.query.spi.MutableQueryOptions;
|
||||||
import org.hibernate.query.spi.NonSelectQueryPlan;
|
import org.hibernate.query.spi.NonSelectQueryPlan;
|
||||||
import org.hibernate.query.spi.ParameterMetadataImplementor;
|
import org.hibernate.query.spi.ParameterMetadataImplementor;
|
||||||
|
import org.hibernate.query.spi.QueryEngine;
|
||||||
import org.hibernate.query.spi.QueryInterpretationCache;
|
import org.hibernate.query.spi.QueryInterpretationCache;
|
||||||
import org.hibernate.query.spi.QueryOptions;
|
import org.hibernate.query.spi.QueryOptions;
|
||||||
import org.hibernate.query.spi.QueryParameterBindings;
|
import org.hibernate.query.spi.QueryParameterBindings;
|
||||||
|
@ -110,8 +111,14 @@ public class QuerySqmImpl<R>
|
||||||
this.hqlString = memento.getHqlString();
|
this.hqlString = memento.getHqlString();
|
||||||
|
|
||||||
final SessionFactoryImplementor factory = producer.getFactory();
|
final SessionFactoryImplementor factory = producer.getFactory();
|
||||||
|
final QueryEngine queryEngine = factory.getQueryEngine();
|
||||||
|
final QueryInterpretationCache interpretationCache = queryEngine.getInterpretationCache();
|
||||||
|
final HqlInterpretation hqlInterpretation = interpretationCache.resolveHqlInterpretation(
|
||||||
|
hqlString,
|
||||||
|
s -> queryEngine.getHqlTranslator().translate( hqlString )
|
||||||
|
);
|
||||||
|
|
||||||
this.sqmStatement = factory.getQueryEngine().getHqlTranslator().translate( hqlString );
|
this.sqmStatement = hqlInterpretation.getSqmStatement();
|
||||||
|
|
||||||
if ( resultType != null ) {
|
if ( resultType != null ) {
|
||||||
if ( sqmStatement instanceof SqmDmlStatement ) {
|
if ( sqmStatement instanceof SqmDmlStatement ) {
|
||||||
|
@ -119,15 +126,8 @@ public class QuerySqmImpl<R>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.resultType = resultType;
|
this.resultType = resultType;
|
||||||
|
this.domainParameterXref = hqlInterpretation.getDomainParameterXref();
|
||||||
if ( sqmStatement.getSqmParameters().isEmpty() ) {
|
this.parameterMetadata = hqlInterpretation.getParameterMetadata();
|
||||||
this.domainParameterXref = DomainParameterXref.empty();
|
|
||||||
this.parameterMetadata = ParameterMetadataImpl.EMPTY;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.domainParameterXref = DomainParameterXref.from( sqmStatement );
|
|
||||||
this.parameterMetadata = new ParameterMetadataImpl( domainParameterXref.getQueryParameters() );
|
|
||||||
}
|
|
||||||
|
|
||||||
this.parameterBindings = QueryParameterBindingsImpl.from( parameterMetadata, producer.getFactory() );
|
this.parameterBindings = QueryParameterBindingsImpl.from( parameterMetadata, producer.getFactory() );
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class QueryStatisticsImpl implements QueryStatistics {
|
||||||
private final Lock readLock;
|
private final Lock readLock;
|
||||||
private final Lock writeLock;
|
private final Lock writeLock;
|
||||||
|
|
||||||
QueryStatisticsImpl(String query) {
|
public QueryStatisticsImpl(String query) {
|
||||||
this.query = query;
|
this.query = query;
|
||||||
ReadWriteLock lock = new ReentrantReadWriteLock();
|
ReadWriteLock lock = new ReentrantReadWriteLock();
|
||||||
this.readLock = lock.readLock();
|
this.readLock = lock.readLock();
|
||||||
|
@ -159,7 +159,7 @@ public class QueryStatisticsImpl implements QueryStatistics {
|
||||||
* @param rows rows count returned
|
* @param rows rows count returned
|
||||||
* @param time time taken
|
* @param time time taken
|
||||||
*/
|
*/
|
||||||
void executed(long rows, long time) {
|
public void executed(long rows, long time) {
|
||||||
// read lock is enough, concurrent updates are supported by the underlying type AtomicLong
|
// read lock is enough, concurrent updates are supported by the underlying type AtomicLong
|
||||||
// this only guards executed(long, long) to be called, when another thread is executing getExecutionAvgTime()
|
// this only guards executed(long, long) to be called, when another thread is executing getExecutionAvgTime()
|
||||||
readLock.lock();
|
readLock.lock();
|
||||||
|
|
|
@ -23,21 +23,21 @@ import org.hibernate.internal.util.collections.BoundedConcurrentHashMap;
|
||||||
*
|
*
|
||||||
* @author Sanne Grinovero
|
* @author Sanne Grinovero
|
||||||
*/
|
*/
|
||||||
final class StatsNamedContainer<V> {
|
public final class StatsNamedContainer<V> {
|
||||||
|
|
||||||
private final ConcurrentMap<String,V> map;
|
private final ConcurrentMap<String,V> map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a bounded container - based on BoundedConcurrentHashMap
|
* Creates a bounded container - based on BoundedConcurrentHashMap
|
||||||
*/
|
*/
|
||||||
StatsNamedContainer(int capacity, int concurrencyLevel) {
|
public StatsNamedContainer(int capacity, int concurrencyLevel) {
|
||||||
this.map = new BoundedConcurrentHashMap( capacity, concurrencyLevel, BoundedConcurrentHashMap.Eviction.LRU );
|
this.map = new BoundedConcurrentHashMap( capacity, concurrencyLevel, BoundedConcurrentHashMap.Eviction.LRU );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an unbounded container - based on ConcurrentHashMap
|
* Creates an unbounded container - based on ConcurrentHashMap
|
||||||
*/
|
*/
|
||||||
StatsNamedContainer() {
|
public StatsNamedContainer() {
|
||||||
this.map = new ConcurrentHashMap<>( );
|
this.map = new ConcurrentHashMap<>( );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,65 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.connection;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
|
|
||||||
import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
|
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Vlad Mihalcea
|
|
||||||
*/
|
|
||||||
public class DriverManagerConnectionProviderValidationConfigTest extends BaseEntityManagerFunctionalTestCase {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
|
||||||
return new Class<?>[] {
|
|
||||||
Event.class
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void addConfigOptions(Map options) {
|
|
||||||
options.put( DriverManagerConnectionProviderImpl.VALIDATION_INTERVAL, 1L );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
|
||||||
Event event = new Event();
|
|
||||||
entityManager.persist( event );
|
|
||||||
|
|
||||||
assertTrue( Thread.getAllStackTraces()
|
|
||||||
.keySet()
|
|
||||||
.stream()
|
|
||||||
.filter( thread -> thread.getName()
|
|
||||||
.equals( "Hibernate Connection Pool Validation Thread" ) && thread.isDaemon() )
|
|
||||||
.map( Thread::isDaemon )
|
|
||||||
.findAny()
|
|
||||||
.isPresent() );
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Entity(name = "Event")
|
|
||||||
public static class Event {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.connection;
|
package org.hibernate.orm.test.connection;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.Driver;
|
import java.sql.Driver;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.connection;
|
package org.hibernate.orm.test.connection;
|
||||||
|
|
||||||
import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
|
import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* 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.orm.test.connection;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
|
||||||
|
|
||||||
|
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||||
|
import org.hibernate.testing.orm.junit.Jpa;
|
||||||
|
import org.hibernate.testing.orm.junit.Setting;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Vlad Mihalcea
|
||||||
|
*/
|
||||||
|
@Jpa(
|
||||||
|
annotatedClasses = { DriverManagerConnectionProviderValidationConfigTest.Event.class },
|
||||||
|
integrationSettings = @Setting(name = DriverManagerConnectionProviderImpl.VALIDATION_INTERVAL, value = "1")
|
||||||
|
)
|
||||||
|
public class DriverManagerConnectionProviderValidationConfigTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test(EntityManagerFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
entityManager -> {
|
||||||
|
Event event = new Event();
|
||||||
|
entityManager.persist( event );
|
||||||
|
|
||||||
|
assertTrue( Thread.getAllStackTraces()
|
||||||
|
.keySet()
|
||||||
|
.stream()
|
||||||
|
.filter( thread -> thread.getName()
|
||||||
|
.equals( "Hibernate Connection Pool Validation Thread" ) && thread.isDaemon() )
|
||||||
|
.map( Thread::isDaemon )
|
||||||
|
.findAny()
|
||||||
|
.isPresent() );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity(name = "Event")
|
||||||
|
public static class Event {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.connection;
|
package org.hibernate.orm.test.connection;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.Driver;
|
import java.sql.Driver;
|
||||||
|
@ -34,7 +34,7 @@ public class DriverManagerRegistrationTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDriverRegistrationUsingLoadClassFails() {
|
public void testDriverRegistrationUsingLoadClassFails() {
|
||||||
final String driverClassName = "org.hibernate.connection.DriverManagerRegistrationTest$TestDriver1";
|
final String driverClassName = "org.hibernate.orm.test.connection.DriverManagerRegistrationTest$TestDriver1";
|
||||||
final String url = "jdbc:hibernate:test";
|
final String url = "jdbc:hibernate:test";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -55,7 +55,7 @@ public class DriverManagerRegistrationTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDriverRegistrationUsingClassForNameSucceeds() {
|
public void testDriverRegistrationUsingClassForNameSucceeds() {
|
||||||
final String driverClassName = "org.hibernate.connection.DriverManagerRegistrationTest$TestDriver2";
|
final String driverClassName = "org.hibernate.orm.test.connection.DriverManagerRegistrationTest$TestDriver2";
|
||||||
final String url = "jdbc:hibernate:test2";
|
final String url = "jdbc:hibernate:test2";
|
||||||
try {
|
try {
|
||||||
Class.forName( driverClassName, true, determineClassLoader() );
|
Class.forName( driverClassName, true, determineClassLoader() );
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.connection;
|
package org.hibernate.orm.test.connection;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.graph;
|
package org.hibernate.orm.test.graph;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -14,6 +14,7 @@ import javax.persistence.EntityGraph;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.Subgraph;
|
import javax.persistence.Subgraph;
|
||||||
|
|
||||||
|
import org.hibernate.graph.GraphParser;
|
||||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
|
@ -4,11 +4,12 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.graph;
|
package org.hibernate.orm.test.graph;
|
||||||
|
|
||||||
import javax.persistence.EntityGraph;
|
import javax.persistence.EntityGraph;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
|
import org.hibernate.graph.EntityGraphs;
|
||||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
|
@ -1,4 +1,4 @@
|
||||||
package org.hibernate.graph;
|
package org.hibernate.orm.test.graph;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.persistence.Basic;
|
import javax.persistence.Basic;
|
|
@ -1,4 +1,4 @@
|
||||||
package org.hibernate.graph;
|
package org.hibernate.orm.test.graph;
|
||||||
|
|
||||||
import javax.persistence.Basic;
|
import javax.persistence.Basic;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.persister.entity;
|
package org.hibernate.orm.test.persister.entity;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
@ -14,31 +14,39 @@ import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import org.hibernate.annotations.Formula;
|
import org.hibernate.annotations.Formula;
|
||||||
import org.hibernate.dialect.H2Dialect;
|
import org.hibernate.persister.entity.AbstractEntityPersister;
|
||||||
|
|
||||||
import org.hibernate.testing.RequiresDialect;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.orm.junit.FailureExpected;
|
||||||
import org.junit.Test;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mykhaylo Gnylorybov
|
* @author Mykhaylo Gnylorybov
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractSchemaSubstitutionFormulaTest extends BaseCoreFunctionalTestCase {
|
@DomainModel(annotatedClasses = {
|
||||||
|
AbstractSchemaSubstitutionFormulaTest.FooBar.class,
|
||||||
|
AbstractSchemaSubstitutionFormulaTest.Bar.class,
|
||||||
|
AbstractSchemaSubstitutionFormulaTest.Foo.class
|
||||||
|
})
|
||||||
|
@SessionFactory
|
||||||
|
public abstract class AbstractSchemaSubstitutionFormulaTest {
|
||||||
|
|
||||||
protected static final String SCHEMA_PLACEHOLDER = "h-schema";
|
protected static final String SCHEMA_PLACEHOLDER = "h-schema";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test(SessionFactoryScope scope) {
|
||||||
final String className = FooBar.class.getName();
|
final String className = FooBar.class.getName();
|
||||||
final AbstractEntityPersister persister = (AbstractEntityPersister) sessionFactory()
|
final AbstractEntityPersister persister = (AbstractEntityPersister) scope.getSessionFactory()
|
||||||
.getMetamodel().entityPersister( className );
|
.getMetamodel().entityPersister( className );
|
||||||
final String formula = persister.getSubclassFormulaTemplateClosure()[0];
|
final String formula = persister.getSubclassPropertyFormulaTemplateClosure()[persister.getPropertyIndex( "isValid" )][0];
|
||||||
|
validate( formula );
|
||||||
|
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
scope.inTransaction( session -> {
|
||||||
Foo foo = new Foo();
|
Foo foo = new Foo();
|
||||||
foo.id = 1;
|
foo.id = 1;
|
||||||
foo.name = "fooName";
|
foo.name = "fooName";
|
||||||
|
@ -57,7 +65,7 @@ public abstract class AbstractSchemaSubstitutionFormulaTest extends BaseCoreFunc
|
||||||
session.persist( fooBar );
|
session.persist( fooBar );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
scope.inTransaction( session -> {
|
||||||
FooBar entity = session.find( FooBar.class, 3 );
|
FooBar entity = session.find( FooBar.class, 3 );
|
||||||
assertTrue( "Invalid result of formula expression: ", entity.isValid );
|
assertTrue( "Invalid result of formula expression: ", entity.isValid );
|
||||||
} );
|
} );
|
||||||
|
@ -67,15 +75,6 @@ public abstract class AbstractSchemaSubstitutionFormulaTest extends BaseCoreFunc
|
||||||
|
|
||||||
abstract void validate(String formula);
|
abstract void validate(String formula);
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
|
||||||
return new Class[] {
|
|
||||||
FooBar.class,
|
|
||||||
Bar.class,
|
|
||||||
Foo.class
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Entity(name = "FOOBAR")
|
@Entity(name = "FOOBAR")
|
||||||
@Table(name = "FOOBAR")
|
@Table(name = "FOOBAR")
|
||||||
public static class FooBar {
|
public static class FooBar {
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.persister.entity;
|
package org.hibernate.orm.test.persister.entity;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
|
@ -20,12 +20,18 @@ import org.hibernate.annotations.SQLDelete;
|
||||||
import org.hibernate.annotations.SQLInsert;
|
import org.hibernate.annotations.SQLInsert;
|
||||||
import org.hibernate.annotations.SQLUpdate;
|
import org.hibernate.annotations.SQLUpdate;
|
||||||
import org.hibernate.dialect.H2Dialect;
|
import org.hibernate.dialect.H2Dialect;
|
||||||
|
import org.hibernate.persister.entity.AbstractEntityPersister;
|
||||||
|
import org.hibernate.persister.entity.SingleTableEntityPersister;
|
||||||
|
|
||||||
import org.hibernate.testing.RequiresDialect;
|
import org.hibernate.testing.RequiresDialect;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.junit.Test;
|
import org.hibernate.testing.orm.junit.FailureExpected;
|
||||||
|
import org.hibernate.testing.orm.junit.NotImplementedYet;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
@ -33,22 +39,19 @@ import static org.junit.Assert.assertNull;
|
||||||
/**
|
/**
|
||||||
* @author Laabidi RAISSI
|
* @author Laabidi RAISSI
|
||||||
*/
|
*/
|
||||||
|
@DomainModel(annotatedClasses = {
|
||||||
|
CustomSqlSchemaResolvingIdentityTest.CustomEntity.class, CustomSqlSchemaResolvingIdentityTest.Dummy.class
|
||||||
|
})
|
||||||
|
@SessionFactory
|
||||||
@RequiresDialect(H2Dialect.class)
|
@RequiresDialect(H2Dialect.class)
|
||||||
public class CustomSqlSchemaResolvingIdentityTest extends BaseCoreFunctionalTestCase {
|
public class CustomSqlSchemaResolvingIdentityTest {
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
|
||||||
return new Class[]{
|
|
||||||
CustomEntity.class, Dummy.class
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSchemaNotReplacedInCustomSQL() throws Exception {
|
public void testSchemaNotReplacedInCustomSQL(SessionFactoryScope scope) throws Exception {
|
||||||
|
|
||||||
String className = CustomEntity.class.getName();
|
String className = CustomEntity.class.getName();
|
||||||
|
|
||||||
final AbstractEntityPersister persister = (AbstractEntityPersister) sessionFactory().getEntityPersister( className );
|
final AbstractEntityPersister persister = (AbstractEntityPersister) scope.getSessionFactory().getEntityPersister( className );
|
||||||
String insertQuery = persister.getSQLInsertStrings()[0];
|
String insertQuery = persister.getSQLInsertStrings()[0];
|
||||||
String updateQuery = persister.getSQLUpdateStrings()[0];
|
String updateQuery = persister.getSQLUpdateStrings()[0];
|
||||||
String deleteQuery = persister.getSQLDeleteStrings()[0];
|
String deleteQuery = persister.getSQLDeleteStrings()[0];
|
||||||
|
@ -62,26 +65,26 @@ public class CustomSqlSchemaResolvingIdentityTest extends BaseCoreFunctionalTest
|
||||||
assertEquals( "Incorrect custom SQL for update in Entity: " + className,
|
assertEquals( "Incorrect custom SQL for update in Entity: " + className,
|
||||||
"UPDATE FOO SET name = ? WHERE id = ? ", updateQuery );
|
"UPDATE FOO SET name = ? WHERE id = ? ", updateQuery );
|
||||||
|
|
||||||
CustomEntity _entitty = doInHibernate( this::sessionFactory, session -> {
|
CustomEntity _entitty = scope.fromTransaction( session -> {
|
||||||
CustomEntity entity = new CustomEntity();
|
CustomEntity entity = new CustomEntity();
|
||||||
session.persist( entity );
|
session.persist( entity );
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
scope.inTransaction( session -> {
|
||||||
CustomEntity entity = session.find( CustomEntity.class, 1 );
|
CustomEntity entity = session.find( CustomEntity.class, 1 );
|
||||||
assertNotNull(entity);
|
assertNotNull(entity);
|
||||||
|
|
||||||
entity.name = "Vlad";
|
entity.name = "Vlad";
|
||||||
} );
|
} );
|
||||||
|
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
scope.inTransaction( session -> {
|
||||||
CustomEntity entity = session.find( CustomEntity.class, _entitty.id );
|
CustomEntity entity = session.find( CustomEntity.class, _entitty.id );
|
||||||
session.delete( entity );
|
session.delete( entity );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
scope.inTransaction( session -> {
|
||||||
CustomEntity entity = session.find( CustomEntity.class, _entitty.id );
|
CustomEntity entity = session.find( CustomEntity.class, _entitty.id );
|
||||||
assertNull(entity);
|
assertNull(entity);
|
||||||
} );
|
} );
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.persister.entity;
|
package org.hibernate.orm.test.persister.entity;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
@ -17,11 +17,16 @@ import org.hibernate.annotations.ResultCheckStyle;
|
||||||
import org.hibernate.annotations.SQLDelete;
|
import org.hibernate.annotations.SQLDelete;
|
||||||
import org.hibernate.annotations.SQLInsert;
|
import org.hibernate.annotations.SQLInsert;
|
||||||
import org.hibernate.annotations.SQLUpdate;
|
import org.hibernate.annotations.SQLUpdate;
|
||||||
|
import org.hibernate.persister.entity.AbstractEntityPersister;
|
||||||
|
import org.hibernate.persister.entity.SingleTableEntityPersister;
|
||||||
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.junit.Test;
|
import org.hibernate.testing.orm.junit.NotImplementedYet;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
@ -29,21 +34,18 @@ import static org.junit.Assert.assertNull;
|
||||||
/**
|
/**
|
||||||
* @author Laabidi RAISSI
|
* @author Laabidi RAISSI
|
||||||
*/
|
*/
|
||||||
public class CustomSqlSchemaResolvingTest extends BaseCoreFunctionalTestCase {
|
@DomainModel(annotatedClasses = {
|
||||||
|
CustomSqlSchemaResolvingTest.CustomEntity.class, CustomSqlSchemaResolvingTest.Dummy.class
|
||||||
@Override
|
})
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
@SessionFactory
|
||||||
return new Class[]{
|
public class CustomSqlSchemaResolvingTest {
|
||||||
CustomEntity.class, Dummy.class
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSchemaNotReplacedInCustomSQL() throws Exception {
|
public void testSchemaNotReplacedInCustomSQL(SessionFactoryScope scope) throws Exception {
|
||||||
|
|
||||||
String className = CustomEntity.class.getName();
|
String className = CustomEntity.class.getName();
|
||||||
|
|
||||||
final AbstractEntityPersister persister = (AbstractEntityPersister) sessionFactory().getEntityPersister( className );
|
final AbstractEntityPersister persister = (AbstractEntityPersister) scope.getSessionFactory().getEntityPersister( className );
|
||||||
String insertQuery = persister.getSQLInsertStrings()[0];
|
String insertQuery = persister.getSQLInsertStrings()[0];
|
||||||
String updateQuery = persister.getSQLUpdateStrings()[0];
|
String updateQuery = persister.getSQLUpdateStrings()[0];
|
||||||
String deleteQuery = persister.getSQLDeleteStrings()[0];
|
String deleteQuery = persister.getSQLDeleteStrings()[0];
|
||||||
|
@ -57,25 +59,25 @@ public class CustomSqlSchemaResolvingTest extends BaseCoreFunctionalTestCase {
|
||||||
assertEquals( "Incorrect custom SQL for update in Entity: " + className,
|
assertEquals( "Incorrect custom SQL for update in Entity: " + className,
|
||||||
"UPDATE FOO SET name = ? WHERE id = ? ", updateQuery );
|
"UPDATE FOO SET name = ? WHERE id = ? ", updateQuery );
|
||||||
|
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
scope.inTransaction( session -> {
|
||||||
CustomEntity entity = new CustomEntity();
|
CustomEntity entity = new CustomEntity();
|
||||||
entity.id = 1;
|
entity.id = 1;
|
||||||
session.persist( entity );
|
session.persist( entity );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
scope.inTransaction( session -> {
|
||||||
CustomEntity entity = session.find( CustomEntity.class, 1 );
|
CustomEntity entity = session.find( CustomEntity.class, 1 );
|
||||||
assertNotNull(entity);
|
assertNotNull(entity);
|
||||||
|
|
||||||
entity.name = "Vlad";
|
entity.name = "Vlad";
|
||||||
} );
|
} );
|
||||||
|
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
scope.inTransaction( session -> {
|
||||||
CustomEntity entity = session.find( CustomEntity.class, 1 );
|
CustomEntity entity = session.find( CustomEntity.class, 1 );
|
||||||
session.delete( entity );
|
session.delete( entity );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
scope.inTransaction( session -> {
|
||||||
CustomEntity entity = session.find( CustomEntity.class, 1 );
|
CustomEntity entity = session.find( CustomEntity.class, 1 );
|
||||||
assertNull(entity);
|
assertNull(entity);
|
||||||
} );
|
} );
|
|
@ -4,11 +4,12 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.persister.entity;
|
package org.hibernate.orm.test.persister.entity;
|
||||||
|
|
||||||
import org.hibernate.dialect.H2Dialect;
|
import org.hibernate.dialect.H2Dialect;
|
||||||
|
|
||||||
import org.hibernate.testing.RequiresDialect;
|
|
||||||
|
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* 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.orm.test.persister.entity;
|
||||||
|
|
||||||
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
|
import org.hibernate.dialect.H2Dialect;
|
||||||
|
|
||||||
|
|
||||||
|
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||||
|
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||||
|
import org.hibernate.testing.orm.junit.Setting;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
@RequiresDialect(H2Dialect.class)
|
||||||
|
@ServiceRegistry(settings = {
|
||||||
|
@Setting( name = AvailableSettings.DEFAULT_SCHEMA, value = FormulaTemplateSchemaSubstitutionTest.CUSTOM_SCHEMA),
|
||||||
|
@Setting( name = AvailableSettings.HBM2DDL_CREATE_SCHEMAS, value = "true")
|
||||||
|
})
|
||||||
|
public class FormulaTemplateSchemaSubstitutionTest extends AbstractSchemaSubstitutionFormulaTest {
|
||||||
|
|
||||||
|
static final String CUSTOM_SCHEMA = "CUSTOM_SCHEMA";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void validate(String formula) {
|
||||||
|
assertEquals( "Formula should not contain {} characters",
|
||||||
|
4, formula.split( CUSTOM_SCHEMA + ".", -1 ).length - 1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,6 @@
|
||||||
package org.hibernate.persister.entity;
|
package org.hibernate.orm.test.persister.entity;
|
||||||
|
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.FetchType;
|
import javax.persistence.FetchType;
|
||||||
|
@ -18,31 +14,25 @@ import org.hibernate.annotations.JoinColumnOrFormula;
|
||||||
import org.hibernate.annotations.JoinColumnsOrFormulas;
|
import org.hibernate.annotations.JoinColumnsOrFormulas;
|
||||||
import org.hibernate.annotations.JoinFormula;
|
import org.hibernate.annotations.JoinFormula;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.junit.Before;
|
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||||
import org.junit.Test;
|
import org.hibernate.testing.orm.junit.Jpa;
|
||||||
|
import org.hibernate.testing.orm.junit.Setting;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@TestForIssue(jiraKey = "HHH-14223")
|
@TestForIssue(jiraKey = "HHH-14223")
|
||||||
public class JoinFormulaImplicitJoinTest extends BaseEntityManagerFunctionalTestCase {
|
@Jpa(annotatedClasses = {
|
||||||
@Override
|
JoinFormulaImplicitJoinTest.Person.class, JoinFormulaImplicitJoinTest.PersonVersion.class
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
}, properties = {
|
||||||
return new Class<?>[] {
|
@Setting(name = AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, value = "true")
|
||||||
Person.class, PersonVersion.class
|
})
|
||||||
};
|
public class JoinFormulaImplicitJoinTest {
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@BeforeEach
|
||||||
protected void addConfigOptions(Map options) {
|
public void setUp(EntityManagerFactoryScope scope) {
|
||||||
options.put(
|
scope.inTransaction(entityManager -> {
|
||||||
AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS,
|
|
||||||
Boolean.TRUE
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
|
||||||
final Person person = new Person();
|
final Person person = new Person();
|
||||||
entityManager.persist(person);
|
entityManager.persist(person);
|
||||||
|
|
||||||
|
@ -61,8 +51,8 @@ public class JoinFormulaImplicitJoinTest extends BaseEntityManagerFunctionalTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImplicitJoin() {
|
public void testImplicitJoin(EntityManagerFactoryScope scope) {
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
scope.inTransaction(entityManager -> {
|
||||||
entityManager.createQuery(
|
entityManager.createQuery(
|
||||||
"SELECT person\n" +
|
"SELECT person\n" +
|
||||||
"FROM Person AS person\n" +
|
"FROM Person AS person\n" +
|
|
@ -0,0 +1,34 @@
|
||||||
|
package org.hibernate.orm.test.procedure.internal;
|
||||||
|
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
|
||||||
|
import org.hibernate.dialect.H2Dialect;
|
||||||
|
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||||
|
import org.hibernate.testing.orm.junit.Jpa;
|
||||||
|
import org.hibernate.testing.orm.junit.NotImplementedYet;
|
||||||
|
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nathan Xu
|
||||||
|
*/
|
||||||
|
@Jpa
|
||||||
|
public class ProcedureCallImplTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue( jiraKey = "HHH-13644" )
|
||||||
|
@RequiresDialect( H2Dialect.class )
|
||||||
|
@NotImplementedYet(reason = "org.hibernate.procedure.internal.ProcedureCallImpl.buildOutputs not yet implemented")
|
||||||
|
public void testNoNullPointerExceptionThrown(EntityManagerFactoryScope scope) {
|
||||||
|
scope.inTransaction( em -> {
|
||||||
|
em.createNativeQuery("CREATE ALIAS GET_RANDOM_VALUE FOR \"java.lang.Math.random\";").executeUpdate();
|
||||||
|
Query query = em.createStoredProcedureQuery("GET_RANDOM_VALUE");
|
||||||
|
Stream stream = query.getResultStream();
|
||||||
|
Assert.assertEquals(1, stream.count());
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.property;
|
package org.hibernate.orm.test.property;
|
||||||
|
|
||||||
import org.hibernate.property.access.internal.PropertyAccessStrategyBasicImpl;
|
import org.hibernate.property.access.internal.PropertyAccessStrategyBasicImpl;
|
||||||
import org.hibernate.property.access.spi.PropertyAccess;
|
import org.hibernate.property.access.spi.PropertyAccess;
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* 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.orm.test.property;
|
||||||
|
|
||||||
|
|
||||||
|
import org.hibernate.Hibernate;
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Michael Rudolf
|
||||||
|
*/
|
||||||
|
@DomainModel(annotatedClasses = {
|
||||||
|
Order.class,
|
||||||
|
Item.class
|
||||||
|
})
|
||||||
|
@SessionFactory
|
||||||
|
public class DirectPropertyAccessorTest {
|
||||||
|
@Test
|
||||||
|
@TestForIssue( jiraKey="HHH-3718" )
|
||||||
|
public void testDirectIdPropertyAccess(SessionFactoryScope scope) throws Exception {
|
||||||
|
scope.inTransaction( s -> {
|
||||||
|
Item i = new Item();
|
||||||
|
s.persist( i );
|
||||||
|
Order o = new Order();
|
||||||
|
o.setOrderNumber( 1 );
|
||||||
|
o.getItems().add( i );
|
||||||
|
s.persist( o );
|
||||||
|
s.flush();
|
||||||
|
s.clear();
|
||||||
|
|
||||||
|
o = ( Order ) s.load( Order.class, 1 );
|
||||||
|
assertFalse( Hibernate.isInitialized( o ) );
|
||||||
|
o.getOrderNumber();
|
||||||
|
// If you mapped with field access, any method, except id, call initializes the proxy
|
||||||
|
assertFalse( Hibernate.isInitialized( o ) );
|
||||||
|
o.getName();
|
||||||
|
assertTrue( Hibernate.isInitialized( o ) );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.property;
|
package org.hibernate.orm.test.property;
|
||||||
|
|
||||||
import javax.persistence.Access;
|
import javax.persistence.Access;
|
||||||
import javax.persistence.AccessType;
|
import javax.persistence.AccessType;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.property;
|
package org.hibernate.orm.test.property;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
@ -12,9 +12,11 @@ import javax.persistence.Table;
|
||||||
import javax.persistence.Transient;
|
import javax.persistence.Transient;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.hibernate.testing.transaction.TransactionUtil;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
import org.junit.Test;
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.hamcrest.core.Is.is;
|
import static org.hamcrest.core.Is.is;
|
||||||
import static org.hamcrest.core.IsNull.nullValue;
|
import static org.hamcrest.core.IsNull.nullValue;
|
||||||
|
@ -23,49 +25,49 @@ import static org.junit.Assert.assertThat;
|
||||||
/**
|
/**
|
||||||
* @author Andrea Boriero
|
* @author Andrea Boriero
|
||||||
*/
|
*/
|
||||||
|
@SessionFactory
|
||||||
|
@DomainModel(annotatedClasses = {
|
||||||
|
GetAndIsVariantGetterWithTransientAnnotationTest.TestEntity.class,
|
||||||
|
GetAndIsVariantGetterWithTransientAnnotationTest.SecondTestEntity.class
|
||||||
|
})
|
||||||
@TestForIssue(jiraKey = "HHH-11716")
|
@TestForIssue(jiraKey = "HHH-11716")
|
||||||
public class GetAndIsVariantGetterWithTransientAnnotationTest extends BaseCoreFunctionalTestCase {
|
public class GetAndIsVariantGetterWithTransientAnnotationTest {
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
|
||||||
return new Class[] {TestEntity.class, SecondTestEntity.class};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAndIsVariantCanHaveDifferentReturnValueWhenOneHasATransientAnnotation() {
|
public void testGetAndIsVariantCanHaveDifferentReturnValueWhenOneHasATransientAnnotation(SessionFactoryScope scope) {
|
||||||
TransactionUtil.doInHibernate( this::sessionFactory, session1 -> {
|
scope.inTransaction( session1 -> {
|
||||||
TestEntity entity = new TestEntity();
|
TestEntity entity = new TestEntity();
|
||||||
entity.setId( 1L );
|
entity.setId( 1L );
|
||||||
entity.setChecked( true );
|
entity.setChecked( true );
|
||||||
session1.save( entity );
|
session1.save( entity );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
TransactionUtil.doInHibernate( this::sessionFactory, session1 -> {
|
scope.inTransaction( session1 -> {
|
||||||
final TestEntity entity = session1.find( TestEntity.class, 1L );
|
final TestEntity entity = session1.find( TestEntity.class, 1L );
|
||||||
assertThat( entity.isChecked(), is( true ) );
|
assertThat( entity.isChecked(), is( true ) );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
TransactionUtil.doInHibernate( this::sessionFactory, session1 -> {
|
scope.inTransaction( session1 -> {
|
||||||
final TestEntity entity = session1.find( TestEntity.class, 1L );
|
final TestEntity entity = session1.find( TestEntity.class, 1L );
|
||||||
entity.setChecked( null );
|
entity.setChecked( null );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
TransactionUtil.doInHibernate( this::sessionFactory, session1 -> {
|
scope.inTransaction( session1 -> {
|
||||||
final TestEntity entity = session1.find( TestEntity.class, 1L );
|
final TestEntity entity = session1.find( TestEntity.class, 1L );
|
||||||
assertThat( entity.isChecked(), is( nullValue() ) );
|
assertThat( entity.isChecked(), is( nullValue() ) );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBothGetterAndIsVariantAreIgnoredWhenMarkedTransient() {
|
public void testBothGetterAndIsVariantAreIgnoredWhenMarkedTransient(SessionFactoryScope scope) {
|
||||||
TransactionUtil.doInHibernate( this::sessionFactory, session1 -> {
|
scope.inTransaction( session1 -> {
|
||||||
SecondTestEntity entity = new SecondTestEntity();
|
SecondTestEntity entity = new SecondTestEntity();
|
||||||
entity.setId( 1L );
|
entity.setId( 1L );
|
||||||
entity.setChecked( true );
|
entity.setChecked( true );
|
||||||
session1.save( entity );
|
session1.save( entity );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
TransactionUtil.doInHibernate( this::sessionFactory, session1 -> {
|
scope.inTransaction( session1 -> {
|
||||||
final SecondTestEntity entity = session1.find( SecondTestEntity.class, 1L );
|
final SecondTestEntity entity = session1.find( SecondTestEntity.class, 1L );
|
||||||
assertThat( entity.getChecked(), is( nullValue() ) );
|
assertThat( entity.getChecked(), is( nullValue() ) );
|
||||||
} );
|
} );
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
// $Id$
|
// $Id$
|
||||||
|
|
||||||
package org.hibernate.property;
|
package org.hibernate.orm.test.property;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
// $Id$
|
// $Id$
|
||||||
|
|
||||||
package org.hibernate.property;
|
package org.hibernate.orm.test.property;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.property;
|
package org.hibernate.orm.test.property;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
|
@ -1,7 +1,11 @@
|
||||||
package org.hibernate.property.access.spi;
|
package org.hibernate.orm.test.property.access.spi;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import org.hibernate.property.access.spi.Getter;
|
||||||
|
import org.hibernate.property.access.spi.GetterFieldImpl;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -15,13 +19,13 @@ public class GetterFieldImplTest {
|
||||||
public void testGet() throws Exception {
|
public void testGet() throws Exception {
|
||||||
Target target = new Target();
|
Target target = new Target();
|
||||||
|
|
||||||
assertEquals( true, getter( "active" ).get( target ) );
|
Assert.assertEquals( true, getter( "active" ).get( target ) );
|
||||||
assertEquals( (byte) 2, getter( "children" ).get( target ) );
|
Assert.assertEquals( (byte) 2, getter( "children" ).get( target ) );
|
||||||
assertEquals( 'M', getter( "gender" ).get( target ) );
|
Assert.assertEquals( 'M', getter( "gender" ).get( target ) );
|
||||||
assertEquals( Integer.MAX_VALUE, getter( "code" ).get( target ) );
|
Assert.assertEquals( Integer.MAX_VALUE, getter( "code" ).get( target ) );
|
||||||
assertEquals( Long.MAX_VALUE, getter( "id" ).get( target ) );
|
Assert.assertEquals( Long.MAX_VALUE, getter( "id" ).get( target ) );
|
||||||
assertEquals( (short) 34, getter( "age" ).get( target ) );
|
Assert.assertEquals( (short) 34, getter( "age" ).get( target ) );
|
||||||
assertEquals( "John Doe", getter( "name" ).get( target ) );
|
Assert.assertEquals( "John Doe", getter( "name" ).get( target ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Target {
|
private static class Target {
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.secure;
|
package org.hibernate.orm.test.secure;
|
||||||
|
|
||||||
import java.security.CodeSource;
|
import java.security.CodeSource;
|
||||||
import java.security.Permission;
|
import java.security.Permission;
|
||||||
|
@ -13,7 +13,6 @@ import java.security.Policy;
|
||||||
import java.security.ProtectionDomain;
|
import java.security.ProtectionDomain;
|
||||||
import java.security.Provider;
|
import java.security.Provider;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.security.auth.Subject;
|
import javax.security.auth.Subject;
|
||||||
|
@ -22,37 +21,33 @@ import javax.security.jacc.PolicyContextException;
|
||||||
import javax.security.jacc.PolicyContextHandler;
|
import javax.security.jacc.PolicyContextHandler;
|
||||||
|
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.junit.Test;
|
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||||
|
import org.hibernate.testing.orm.junit.Jpa;
|
||||||
|
import org.hibernate.testing.orm.junit.Setting;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Vlad Mihalcea
|
* @author Vlad Mihalcea
|
||||||
*/
|
*/
|
||||||
|
@Jpa(annotatedClasses = {
|
||||||
|
JaccIntegratorTest.Person.class
|
||||||
|
}, properties = {
|
||||||
|
@Setting( name = AvailableSettings.JACC_ENABLED, value = "true"),
|
||||||
|
@Setting( name = AvailableSettings.JACC_CONTEXT_ID, value = "JACC_CONTEXT_ID"),
|
||||||
|
@Setting( name = "hibernate.jacc.allowed.org.hibernate.secure.Customer", value = "insert")
|
||||||
|
})
|
||||||
@TestForIssue( jiraKey = "HHH-11805" )
|
@TestForIssue( jiraKey = "HHH-11805" )
|
||||||
public class JaccIntegratorTest extends BaseEntityManagerFunctionalTestCase {
|
public class JaccIntegratorTest {
|
||||||
|
|
||||||
@Override
|
@BeforeEach
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
protected void afterEntityManagerFactoryBuilt(EntityManagerFactoryScope scope) {
|
||||||
return new Class<?>[] {
|
scope.getEntityManagerFactory();
|
||||||
Person.class,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void addConfigOptions(Map options) {
|
|
||||||
options.put( AvailableSettings.JACC_ENABLED, Boolean.TRUE.toString() );
|
|
||||||
options.put( AvailableSettings.JACC_CONTEXT_ID, "JACC_CONTEXT_ID" );
|
|
||||||
options.put( "hibernate.jacc.allowed.org.hibernate.secure.Customer", "insert" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void afterEntityManagerFactoryBuilt() {
|
|
||||||
PolicyContextHandler policyContextHandler = new PolicyContextHandler() {
|
PolicyContextHandler policyContextHandler = new PolicyContextHandler() {
|
||||||
@Override
|
@Override
|
||||||
public Object getContext(String key, Object data) throws PolicyContextException {
|
public Object getContext(String key, Object data) throws PolicyContextException {
|
||||||
|
@ -129,10 +124,10 @@ public class JaccIntegratorTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAllow() {
|
public void testAllow(EntityManagerFactoryScope scope) {
|
||||||
setPolicy( true );
|
setPolicy( true );
|
||||||
|
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
scope.inTransaction( entityManager -> {
|
||||||
Person person = new Person();
|
Person person = new Person();
|
||||||
person.id = 1L;
|
person.id = 1L;
|
||||||
person.name = "John Doe";
|
person.name = "John Doe";
|
||||||
|
@ -142,11 +137,11 @@ public class JaccIntegratorTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDisallow() {
|
public void testDisallow(EntityManagerFactoryScope scope) {
|
||||||
setPolicy( false );
|
setPolicy( false );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
scope.inTransaction( entityManager -> {
|
||||||
Person person = new Person();
|
Person person = new Person();
|
||||||
person.id = 1L;
|
person.id = 1L;
|
||||||
person.name = "John Doe";
|
person.name = "John Doe";
|
|
@ -4,11 +4,10 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.serialization;
|
package org.hibernate.orm.test.serialization;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.FetchType;
|
import javax.persistence.FetchType;
|
||||||
|
@ -18,8 +17,6 @@ import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
|
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.Transaction;
|
|
||||||
import org.hibernate.annotations.Fetch;
|
import org.hibernate.annotations.Fetch;
|
||||||
import org.hibernate.annotations.FetchMode;
|
import org.hibernate.annotations.FetchMode;
|
||||||
import org.hibernate.annotations.LazyCollection;
|
import org.hibernate.annotations.LazyCollection;
|
||||||
|
@ -27,46 +24,41 @@ import org.hibernate.annotations.LazyCollectionOption;
|
||||||
import org.hibernate.annotations.LazyToOne;
|
import org.hibernate.annotations.LazyToOne;
|
||||||
import org.hibernate.annotations.LazyToOneOption;
|
import org.hibernate.annotations.LazyToOneOption;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.cfg.Configuration;
|
|
||||||
import org.hibernate.internal.util.SerializationHelper;
|
import org.hibernate.internal.util.SerializationHelper;
|
||||||
import org.hibernate.proxy.AbstractLazyInitializer;
|
import org.hibernate.proxy.AbstractLazyInitializer;
|
||||||
import org.hibernate.proxy.HibernateProxy;
|
import org.hibernate.proxy.HibernateProxy;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.junit.Before;
|
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||||
import org.junit.Test;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.hibernate.testing.orm.junit.Setting;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Selaron
|
* @author Selaron
|
||||||
*/
|
*/
|
||||||
public class EntityProxySerializationTest extends BaseCoreFunctionalTestCase {
|
@DomainModel(annotatedClasses = {
|
||||||
|
EntityProxySerializationTest.SimpleEntity.class, EntityProxySerializationTest.ChildEntity.class
|
||||||
@Override
|
})
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
@SessionFactory
|
||||||
return new Class[] { SimpleEntity.class, ChildEntity.class };
|
@ServiceRegistry(settings = {
|
||||||
}
|
@Setting( name = AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, value = "true" )
|
||||||
|
})
|
||||||
@Override
|
public class EntityProxySerializationTest {
|
||||||
protected void configure(final Configuration configuration) {
|
|
||||||
// enable LL without TX, which used to cause problems when serializing proxies (see HHH-12720)
|
|
||||||
configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, Boolean.TRUE.toString() );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare and persist a {@link SimpleEntity} with two {@link ChildEntity}.
|
* Prepare and persist a {@link SimpleEntity} with two {@link ChildEntity}.
|
||||||
*/
|
*/
|
||||||
@Before
|
@BeforeEach
|
||||||
public void prepare() {
|
public void prepare(SessionFactoryScope scope) {
|
||||||
final Session s = openSession();
|
scope.inTransaction( s -> {
|
||||||
|
|
||||||
final Transaction t = s.beginTransaction();
|
|
||||||
|
|
||||||
try {
|
|
||||||
final Number count = (Number) s.createQuery("SELECT count(ID) FROM SimpleEntity").getSingleResult();
|
final Number count = (Number) s.createQuery("SELECT count(ID) FROM SimpleEntity").getSingleResult();
|
||||||
if (count.longValue() > 0L) {
|
if (count.longValue() > 0L) {
|
||||||
// entity already added previously
|
// entity already added previously
|
||||||
|
@ -88,23 +80,15 @@ public class EntityProxySerializationTest extends BaseCoreFunctionalTestCase {
|
||||||
s.save( entity );
|
s.save( entity );
|
||||||
s.save( c1 );
|
s.save( c1 );
|
||||||
s.save( c2 );
|
s.save( c2 );
|
||||||
}
|
} );
|
||||||
finally {
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that serializing an initialized proxy will serialize the target instead.
|
* Tests that serializing an initialized proxy will serialize the target instead.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Test
|
@Test
|
||||||
public void testInitializedProxySerializationIfTargetInPersistenceContext() {
|
public void testInitializedProxySerializationIfTargetInPersistenceContext(SessionFactoryScope scope) {
|
||||||
final Session s = openSession();
|
scope.inTransaction( s -> {
|
||||||
|
|
||||||
final Transaction t = s.beginTransaction();
|
|
||||||
try {
|
|
||||||
final ChildEntity child = s.find( ChildEntity.class, 1L );
|
final ChildEntity child = s.find( ChildEntity.class, 1L );
|
||||||
|
|
||||||
final SimpleEntity parent = child.getParent();
|
final SimpleEntity parent = child.getParent();
|
||||||
|
@ -123,13 +107,7 @@ public class EntityProxySerializationTest extends BaseCoreFunctionalTestCase {
|
||||||
// assert the deserialized object is no longer a proxy, but the target of the proxy
|
// assert the deserialized object is no longer a proxy, but the target of the proxy
|
||||||
assertFalse( deserializedParent instanceof HibernateProxy );
|
assertFalse( deserializedParent instanceof HibernateProxy );
|
||||||
assertEquals( "TheParent", deserializedParent.getName() );
|
assertEquals( "TheParent", deserializedParent.getName() );
|
||||||
}
|
} );
|
||||||
finally {
|
|
||||||
if ( t.isActive() ) {
|
|
||||||
t.rollback();
|
|
||||||
}
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,13 +115,9 @@ public class EntityProxySerializationTest extends BaseCoreFunctionalTestCase {
|
||||||
* but whose target has been (separately) added to the persistence context
|
* but whose target has been (separately) added to the persistence context
|
||||||
* will serialize the target instead.
|
* will serialize the target instead.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Test
|
@Test
|
||||||
public void testUninitializedProxySerializationIfTargetInPersistenceContext() {
|
public void testUninitializedProxySerializationIfTargetInPersistenceContext(SessionFactoryScope scope) {
|
||||||
final Session s = openSession();
|
scope.inTransaction( s -> {
|
||||||
|
|
||||||
final Transaction t = s.beginTransaction();
|
|
||||||
try {
|
|
||||||
final ChildEntity child = s.find( ChildEntity.class, 1L );
|
final ChildEntity child = s.find( ChildEntity.class, 1L );
|
||||||
|
|
||||||
final SimpleEntity parent = child.getParent();
|
final SimpleEntity parent = child.getParent();
|
||||||
|
@ -166,13 +140,7 @@ public class EntityProxySerializationTest extends BaseCoreFunctionalTestCase {
|
||||||
// assert the deserialized object is no longer a proxy, but the target of the proxy
|
// assert the deserialized object is no longer a proxy, but the target of the proxy
|
||||||
assertFalse( deserializedParent instanceof HibernateProxy );
|
assertFalse( deserializedParent instanceof HibernateProxy );
|
||||||
assertEquals( "TheParent", deserializedParent.getName() );
|
assertEquals( "TheParent", deserializedParent.getName() );
|
||||||
}
|
} );
|
||||||
finally {
|
|
||||||
if ( t.isActive() ) {
|
|
||||||
t.rollback();
|
|
||||||
}
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -180,19 +148,12 @@ public class EntityProxySerializationTest extends BaseCoreFunctionalTestCase {
|
||||||
* working. The magic is done by {@link AbstractLazyInitializer} who opens a
|
* working. The magic is done by {@link AbstractLazyInitializer} who opens a
|
||||||
* temporary session.
|
* temporary session.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Test
|
@Test
|
||||||
public void testProxyInitializationWithoutTX() {
|
public void testProxyInitializationWithoutTX(SessionFactoryScope scope) {
|
||||||
final Session s = openSession();
|
final SimpleEntity parent = scope.fromTransaction( s -> {
|
||||||
|
|
||||||
final Transaction t = s.beginTransaction();
|
|
||||||
try {
|
|
||||||
final ChildEntity child = s.find( ChildEntity.class, 1L );
|
final ChildEntity child = s.find( ChildEntity.class, 1L );
|
||||||
|
return child.getParent();
|
||||||
final SimpleEntity parent = child.getParent();
|
});
|
||||||
|
|
||||||
t.rollback();
|
|
||||||
session.close();
|
|
||||||
|
|
||||||
// assert we have an uninitialized proxy
|
// assert we have an uninitialized proxy
|
||||||
assertTrue( parent instanceof HibernateProxy );
|
assertTrue( parent instanceof HibernateProxy );
|
||||||
|
@ -203,37 +164,21 @@ public class EntityProxySerializationTest extends BaseCoreFunctionalTestCase {
|
||||||
// assert we have an initialized proxy now
|
// assert we have an initialized proxy now
|
||||||
assertTrue( Hibernate.isInitialized( parent ) );
|
assertTrue( Hibernate.isInitialized( parent ) );
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
if ( t.isActive() ) {
|
|
||||||
t.rollback();
|
|
||||||
}
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that lazy loading without transaction nor open session is generally
|
* Tests that lazy loading without transaction nor open session is generally
|
||||||
* working. The magic is done by {@link AbstractLazyInitializer} who opens a
|
* working. The magic is done by {@link AbstractLazyInitializer} who opens a
|
||||||
* temporary session.
|
* temporary session.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-12720")
|
@TestForIssue(jiraKey = "HHH-12720")
|
||||||
public void testProxyInitializationWithoutTXAfterDeserialization() {
|
public void testProxyInitializationWithoutTXAfterDeserialization(SessionFactoryScope scope) {
|
||||||
final Session s = openSession();
|
final SimpleEntity deserializedParent = scope.fromTransaction( s -> {
|
||||||
|
|
||||||
final Transaction t = s.beginTransaction();
|
|
||||||
try {
|
|
||||||
final ChildEntity child = s.find( ChildEntity.class, 1L );
|
final ChildEntity child = s.find( ChildEntity.class, 1L );
|
||||||
|
|
||||||
final SimpleEntity parent = child.getParent();
|
final SimpleEntity parent = child.getParent();
|
||||||
|
|
||||||
// destroy AbstractLazyInitializer internal state
|
// destroy AbstractLazyInitializer internal state
|
||||||
final SimpleEntity deserializedParent = (SimpleEntity) SerializationHelper.clone( parent );
|
return (SimpleEntity) SerializationHelper.clone( parent );
|
||||||
|
});
|
||||||
t.rollback();
|
|
||||||
session.close();
|
|
||||||
|
|
||||||
// assert we have an uninitialized proxy
|
// assert we have an uninitialized proxy
|
||||||
assertTrue( deserializedParent instanceof HibernateProxy );
|
assertTrue( deserializedParent instanceof HibernateProxy );
|
||||||
assertFalse( Hibernate.isInitialized( deserializedParent ) );
|
assertFalse( Hibernate.isInitialized( deserializedParent ) );
|
||||||
|
@ -243,13 +188,6 @@ public class EntityProxySerializationTest extends BaseCoreFunctionalTestCase {
|
||||||
// assert we have an initialized proxy now
|
// assert we have an initialized proxy now
|
||||||
assertTrue( Hibernate.isInitialized( deserializedParent ) );
|
assertTrue( Hibernate.isInitialized( deserializedParent ) );
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
if ( t.isActive() ) {
|
|
||||||
t.rollback();
|
|
||||||
}
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Entity(name = "SimpleEntity")
|
@Entity(name = "SimpleEntity")
|
||||||
static class SimpleEntity implements Serializable {
|
static class SimpleEntity implements Serializable {
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.serialization;
|
package org.hibernate.orm.test.serialization;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
@ -14,14 +14,15 @@ import java.io.ObjectOutputStream;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.internal.util.ReflectHelper;
|
import org.hibernate.internal.util.ReflectHelper;
|
||||||
|
import org.hibernate.orm.test.serialization.entity.AnEntity;
|
||||||
|
import org.hibernate.orm.test.serialization.entity.PK;
|
||||||
import org.hibernate.property.access.spi.Getter;
|
import org.hibernate.property.access.spi.Getter;
|
||||||
import org.hibernate.property.access.spi.GetterFieldImpl;
|
import org.hibernate.property.access.spi.GetterFieldImpl;
|
||||||
import org.hibernate.property.access.spi.GetterMethodImpl;
|
import org.hibernate.property.access.spi.GetterMethodImpl;
|
||||||
import org.hibernate.property.access.spi.Setter;
|
import org.hibernate.property.access.spi.Setter;
|
||||||
import org.hibernate.property.access.spi.SetterFieldImpl;
|
import org.hibernate.property.access.spi.SetterFieldImpl;
|
||||||
import org.hibernate.property.access.spi.SetterMethodImpl;
|
import org.hibernate.property.access.spi.SetterMethodImpl;
|
||||||
import org.hibernate.serialization.entity.AnEntity;
|
|
||||||
import org.hibernate.serialization.entity.PK;
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
|
@ -4,58 +4,48 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.serialization;
|
package org.hibernate.orm.test.serialization;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.EntityMode;
|
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.Transaction;
|
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.cfg.Configuration;
|
|
||||||
import org.hibernate.internal.util.SerializationHelper;
|
import org.hibernate.internal.util.SerializationHelper;
|
||||||
import org.hibernate.proxy.AbstractLazyInitializer;
|
import org.hibernate.proxy.AbstractLazyInitializer;
|
||||||
import org.hibernate.proxy.HibernateProxy;
|
import org.hibernate.proxy.HibernateProxy;
|
||||||
import org.hibernate.proxy.map.MapProxy;
|
import org.hibernate.proxy.map.MapProxy;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.junit.Before;
|
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||||
import org.junit.Test;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.hibernate.testing.orm.junit.Setting;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Selaron
|
* @author Selaron
|
||||||
*/
|
*/
|
||||||
public class MapProxySerializationTest extends BaseCoreFunctionalTestCase {
|
@DomainModel(xmlMappings = {
|
||||||
|
"org/hibernate/orm/test/serialization/DynamicMapMappings.hbm.xml"
|
||||||
|
})
|
||||||
|
@SessionFactory
|
||||||
|
@ServiceRegistry(settings = {
|
||||||
|
@Setting( name = AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, value = "true" ),
|
||||||
|
@Setting( name = AvailableSettings.DEFAULT_ENTITY_MODE, value = "dynamic-map" )
|
||||||
|
})
|
||||||
|
public class MapProxySerializationTest {
|
||||||
|
|
||||||
@Override
|
@BeforeEach
|
||||||
protected String[] getMappings() {
|
public void prepare(SessionFactoryScope scope) {
|
||||||
return new String[] { "serialization/DynamicMapMappings.hbm.xml" };
|
scope.inTransaction( s -> {
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure(final Configuration configuration) {
|
|
||||||
// enable LL without TX, which used to cause problems when serializing proxies (see HHH-12720)
|
|
||||||
configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, Boolean.TRUE.toString() );
|
|
||||||
|
|
||||||
// dynamic-map by default.
|
|
||||||
configuration.setProperty( AvailableSettings.DEFAULT_ENTITY_MODE, EntityMode.MAP.getExternalName() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void prepare() {
|
|
||||||
final Session s = openSession();
|
|
||||||
|
|
||||||
final Transaction t = s.beginTransaction();
|
|
||||||
|
|
||||||
try {
|
|
||||||
final Number count = (Number) s.createQuery("SELECT count(ID) FROM SimpleEntity").getSingleResult();
|
final Number count = (Number) s.createQuery("SELECT count(ID) FROM SimpleEntity").getSingleResult();
|
||||||
if (count.longValue() > 0L) {
|
if (count.longValue() > 0L) {
|
||||||
// entity already added previously
|
// entity already added previously
|
||||||
|
@ -72,11 +62,7 @@ public class MapProxySerializationTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
s.save( "SimpleEntity", entity );
|
s.save( "SimpleEntity", entity );
|
||||||
s.save( "ChildEntity", c1 );
|
s.save( "ChildEntity", c1 );
|
||||||
}
|
} );
|
||||||
finally {
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,11 +71,8 @@ public class MapProxySerializationTest extends BaseCoreFunctionalTestCase {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-7686")
|
@TestForIssue(jiraKey = "HHH-7686")
|
||||||
public void testInitializedProxySerializationIfTargetInPersistenceContext() {
|
public void testInitializedProxySerializationIfTargetInPersistenceContext(SessionFactoryScope scope) {
|
||||||
final Session s = openSession();
|
scope.inTransaction( s -> {
|
||||||
|
|
||||||
final Transaction t = s.beginTransaction();
|
|
||||||
try {
|
|
||||||
final Map<String, Object> child = (Map<String, Object>) s.load( "ChildEntity", 1L );
|
final Map<String, Object> child = (Map<String, Object>) s.load( "ChildEntity", 1L );
|
||||||
|
|
||||||
final Map<String, Object> parent = (Map<String, Object>) child.get( "parent" );
|
final Map<String, Object> parent = (Map<String, Object>) child.get( "parent" );
|
||||||
|
@ -109,13 +92,7 @@ public class MapProxySerializationTest extends BaseCoreFunctionalTestCase {
|
||||||
// assert the deserialized object is no longer a proxy, but the target of the proxy
|
// assert the deserialized object is no longer a proxy, but the target of the proxy
|
||||||
assertFalse( deserializedParent instanceof HibernateProxy );
|
assertFalse( deserializedParent instanceof HibernateProxy );
|
||||||
assertEquals( "TheParent", deserializedParent.get( "name" ) );
|
assertEquals( "TheParent", deserializedParent.get( "name" ) );
|
||||||
}
|
} );
|
||||||
finally {
|
|
||||||
if ( t.isActive() ) {
|
|
||||||
t.rollback();
|
|
||||||
}
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,11 +103,8 @@ public class MapProxySerializationTest extends BaseCoreFunctionalTestCase {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-7686")
|
@TestForIssue(jiraKey = "HHH-7686")
|
||||||
public void testUninitializedProxySerializationIfTargetInPersistenceContext() {
|
public void testUninitializedProxySerializationIfTargetInPersistenceContext(SessionFactoryScope scope) {
|
||||||
final Session s = openSession();
|
scope.inTransaction( s -> {
|
||||||
|
|
||||||
final Transaction t = s.beginTransaction();
|
|
||||||
try {
|
|
||||||
final Map<String, Object> child = (Map<String, Object>) s.load( "ChildEntity", 1L );
|
final Map<String, Object> child = (Map<String, Object>) s.load( "ChildEntity", 1L );
|
||||||
|
|
||||||
final Map<String, Object> parent = (Map<String, Object>) child.get( "parent" );
|
final Map<String, Object> parent = (Map<String, Object>) child.get( "parent" );
|
||||||
|
@ -154,13 +128,7 @@ public class MapProxySerializationTest extends BaseCoreFunctionalTestCase {
|
||||||
// assert the deserialized object is no longer a proxy, but the target of the proxy
|
// assert the deserialized object is no longer a proxy, but the target of the proxy
|
||||||
assertFalse( deserializedParent instanceof HibernateProxy );
|
assertFalse( deserializedParent instanceof HibernateProxy );
|
||||||
assertEquals( "TheParent", deserializedParent.get( "name" ) );
|
assertEquals( "TheParent", deserializedParent.get( "name" ) );
|
||||||
}
|
} );
|
||||||
finally {
|
|
||||||
if ( t.isActive() ) {
|
|
||||||
t.rollback();
|
|
||||||
}
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -170,18 +138,11 @@ public class MapProxySerializationTest extends BaseCoreFunctionalTestCase {
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testProxyInitializationWithoutTX() {
|
public void testProxyInitializationWithoutTX(SessionFactoryScope scope) {
|
||||||
final Session s = openSession();
|
final Map<String, Object> parent = scope.fromTransaction( s -> {
|
||||||
|
|
||||||
final Transaction t = s.beginTransaction();
|
|
||||||
try {
|
|
||||||
final Map<String, Object> child = (Map<String, Object>) s.load( "ChildEntity", 1L );
|
final Map<String, Object> child = (Map<String, Object>) s.load( "ChildEntity", 1L );
|
||||||
|
return (Map<String, Object>) child.get( "parent" );
|
||||||
final Map<String, Object> parent = (Map<String, Object>) child.get( "parent" );
|
});
|
||||||
|
|
||||||
t.rollback();
|
|
||||||
session.close();
|
|
||||||
|
|
||||||
// assert we have an uninitialized proxy
|
// assert we have an uninitialized proxy
|
||||||
assertTrue( parent instanceof MapProxy );
|
assertTrue( parent instanceof MapProxy );
|
||||||
assertFalse( Hibernate.isInitialized( parent ) );
|
assertFalse( Hibernate.isInitialized( parent ) );
|
||||||
|
@ -191,13 +152,6 @@ public class MapProxySerializationTest extends BaseCoreFunctionalTestCase {
|
||||||
// assert we have an initialized proxy now
|
// assert we have an initialized proxy now
|
||||||
assertTrue( Hibernate.isInitialized( parent ) );
|
assertTrue( Hibernate.isInitialized( parent ) );
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
if ( t.isActive() ) {
|
|
||||||
t.rollback();
|
|
||||||
}
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that lazy loading without transaction nor open session is generally
|
* Tests that lazy loading without transaction nor open session is generally
|
||||||
|
@ -207,21 +161,14 @@ public class MapProxySerializationTest extends BaseCoreFunctionalTestCase {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-7686")
|
@TestForIssue(jiraKey = "HHH-7686")
|
||||||
public void testProxyInitializationWithoutTXAfterDeserialization() {
|
public void testProxyInitializationWithoutTXAfterDeserialization(SessionFactoryScope scope) {
|
||||||
final Session s = openSession();
|
final Map<String, Object> deserializedParent = scope.fromTransaction( s -> {
|
||||||
|
|
||||||
final Transaction t = s.beginTransaction();
|
|
||||||
try {
|
|
||||||
final Map<String, Object> child = (Map<String, Object>) s.load( "ChildEntity", 1L );
|
final Map<String, Object> child = (Map<String, Object>) s.load( "ChildEntity", 1L );
|
||||||
|
|
||||||
final Map<String, Object> parent = (Map<String, Object>) child.get( "parent" );
|
final Map<String, Object> parent = (Map<String, Object>) child.get( "parent" );
|
||||||
|
|
||||||
// destroy AbstractLazyInitializer internal state
|
// destroy AbstractLazyInitializer internal state
|
||||||
final Map<String, Object> deserializedParent =
|
return (Map<String, Object>) SerializationHelper.clone( (Serializable) parent );
|
||||||
(Map<String, Object>) SerializationHelper.clone( (Serializable) parent );
|
});
|
||||||
|
|
||||||
t.rollback();
|
|
||||||
session.close();
|
|
||||||
|
|
||||||
// assert we have an uninitialized proxy
|
// assert we have an uninitialized proxy
|
||||||
assertTrue( deserializedParent instanceof MapProxy );
|
assertTrue( deserializedParent instanceof MapProxy );
|
||||||
|
@ -232,12 +179,5 @@ public class MapProxySerializationTest extends BaseCoreFunctionalTestCase {
|
||||||
// assert we have an initialized proxy now
|
// assert we have an initialized proxy now
|
||||||
assertTrue( Hibernate.isInitialized( deserializedParent ) );
|
assertTrue( Hibernate.isInitialized( deserializedParent ) );
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
if ( t.isActive() ) {
|
|
||||||
t.rollback();
|
|
||||||
}
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.serialization;
|
package org.hibernate.orm.test.serialization;
|
||||||
|
|
||||||
|
|
||||||
import javax.naming.Reference;
|
import javax.naming.Reference;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.serialization.entity;
|
package org.hibernate.orm.test.serialization.entity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class should be in a package that is different from the test
|
* The class should be in a package that is different from the test
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.serialization.entity;
|
package org.hibernate.orm.test.serialization.entity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class should be in a package that is different from the test
|
* This class should be in a package that is different from the test
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
* 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
|
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||||
*/
|
*/
|
||||||
package org.hibernate.service;
|
package org.hibernate.orm.test.service;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.hibernate.service;
|
package org.hibernate.orm.test.service;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
@ -10,6 +10,9 @@ import java.util.concurrent.FutureTask;
|
||||||
|
|
||||||
import org.hibernate.boot.registry.StandardServiceInitiator;
|
import org.hibernate.boot.registry.StandardServiceInitiator;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
|
import org.hibernate.service.NullServiceException;
|
||||||
|
import org.hibernate.service.Service;
|
||||||
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.service.spi.Configurable;
|
import org.hibernate.service.spi.Configurable;
|
||||||
import org.hibernate.service.spi.ServiceRegistryAwareService;
|
import org.hibernate.service.spi.ServiceRegistryAwareService;
|
||||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.service.internal;
|
package org.hibernate.orm.test.service.internal;
|
||||||
|
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.session;
|
package org.hibernate.orm.test.session;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.FetchType;
|
import javax.persistence.FetchType;
|
||||||
|
@ -14,33 +14,30 @@ import javax.persistence.ManyToOne;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
|
||||||
import org.hibernate.proxy.AbstractLazyInitializer;
|
import org.hibernate.proxy.AbstractLazyInitializer;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
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.orm.junit.EntityManagerFactoryScope;
|
||||||
|
import org.hibernate.testing.orm.junit.Jpa;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Vlad Mihalcea
|
* @author Vlad Mihalcea
|
||||||
*/
|
*/
|
||||||
public class AssociateEntityWithTwoSessionsTest extends BaseEntityManagerFunctionalTestCase {
|
@Jpa(annotatedClasses = {
|
||||||
|
AssociateEntityWithTwoSessionsTest.Location.class,
|
||||||
@Override
|
AssociateEntityWithTwoSessionsTest.Event.class
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
})
|
||||||
return new Class[] {
|
public class AssociateEntityWithTwoSessionsTest {
|
||||||
Location.class,
|
|
||||||
Event.class
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public LoggerInspectionRule logInspection = new LoggerInspectionRule(
|
public LoggerInspectionRule logInspection = new LoggerInspectionRule(
|
||||||
|
@ -48,7 +45,7 @@ public class AssociateEntityWithTwoSessionsTest extends BaseEntityManagerFunctio
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-12216" )
|
@TestForIssue( jiraKey = "HHH-12216" )
|
||||||
public void test() {
|
public void test(EntityManagerFactoryScope scope) {
|
||||||
|
|
||||||
final Location location = new Location();
|
final Location location = new Location();
|
||||||
location.setCity( "Cluj" );
|
location.setCity( "Cluj" );
|
||||||
|
@ -56,7 +53,7 @@ public class AssociateEntityWithTwoSessionsTest extends BaseEntityManagerFunctio
|
||||||
final Event event = new Event();
|
final Event event = new Event();
|
||||||
event.setLocation( location );
|
event.setLocation( location );
|
||||||
|
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
scope.inTransaction( entityManager -> {
|
||||||
entityManager.persist( location );
|
entityManager.persist( location );
|
||||||
entityManager.persist( event );
|
entityManager.persist( event );
|
||||||
} );
|
} );
|
||||||
|
@ -64,12 +61,12 @@ public class AssociateEntityWithTwoSessionsTest extends BaseEntityManagerFunctio
|
||||||
final Triggerable triggerable = logInspection.watchForLogMessages( "HHH000485" );
|
final Triggerable triggerable = logInspection.watchForLogMessages( "HHH000485" );
|
||||||
triggerable.reset();
|
triggerable.reset();
|
||||||
|
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
scope.inTransaction( entityManager -> {
|
||||||
Event event1 = entityManager.find( Event.class, event.id );
|
Event event1 = entityManager.find( Event.class, event.id );
|
||||||
Location location1 = event1.getLocation();
|
Location location1 = event1.getLocation();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
doInJPA( this::entityManagerFactory, _entityManager -> {
|
scope.inTransaction( _entityManager -> {
|
||||||
_entityManager.unwrap( Session.class ).update( location1 );
|
_entityManager.unwrap( Session.class ).update( location1 );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
@ -80,7 +77,7 @@ public class AssociateEntityWithTwoSessionsTest extends BaseEntityManagerFunctio
|
||||||
} );
|
} );
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"HHH000485: Illegally attempted to associate a proxy for entity [org.hibernate.session.AssociateEntityWithTwoSessionsTest$Location] with id [1] with two open sessions.",
|
"HHH000485: Illegally attempted to associate a proxy for entity [org.hibernate.orm.test.session.AssociateEntityWithTwoSessionsTest$Location] with id [1] with two open sessions.",
|
||||||
triggerable.triggerMessage()
|
triggerable.triggerMessage()
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.sharedSession;
|
package org.hibernate.orm.test.sharedSession;
|
||||||
|
|
||||||
import org.hibernate.FlushMode;
|
import org.hibernate.FlushMode;
|
||||||
import org.hibernate.IrrelevantEntity;
|
import org.hibernate.IrrelevantEntity;
|
||||||
|
@ -18,8 +18,9 @@ import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
|
||||||
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
|
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.junit.Test;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -27,6 +28,8 @@ import java.util.Collection;
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
@ -36,11 +39,13 @@ import static org.junit.Assert.assertTrue;
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase {
|
@DomainModel(annotatedClasses = IrrelevantEntity.class)
|
||||||
|
@SessionFactory
|
||||||
|
public class SessionWithSharedConnectionTest {
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-7090" )
|
@TestForIssue( jiraKey = "HHH-7090" )
|
||||||
public void testSharedTransactionContextSessionClosing() {
|
public void testSharedTransactionContextSessionClosing(SessionFactoryScope scope) {
|
||||||
Session session = sessionFactory().openSession();
|
Session session = scope.getSessionFactory().openSession();
|
||||||
session.getTransaction().begin();
|
session.getTransaction().begin();
|
||||||
|
|
||||||
Session secondSession = session.sessionWithOptions()
|
Session secondSession = session.sessionWithOptions()
|
||||||
|
@ -81,8 +86,8 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-7090" )
|
@TestForIssue( jiraKey = "HHH-7090" )
|
||||||
public void testSharedTransactionContextAutoClosing() {
|
public void testSharedTransactionContextAutoClosing(SessionFactoryScope scope) {
|
||||||
Session session = sessionFactory().openSession();
|
Session session = scope.getSessionFactory().openSession();
|
||||||
session.getTransaction().begin();
|
session.getTransaction().begin();
|
||||||
|
|
||||||
// COMMIT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// COMMIT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
@ -108,7 +113,7 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
||||||
|
|
||||||
// ROLLBACK ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// ROLLBACK ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
session = sessionFactory().openSession();
|
session = scope.getSessionFactory().openSession();
|
||||||
session.getTransaction().begin();
|
session.getTransaction().begin();
|
||||||
|
|
||||||
secondSession = session.sessionWithOptions()
|
secondSession = session.sessionWithOptions()
|
||||||
|
@ -134,7 +139,7 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
||||||
// @Test
|
// @Test
|
||||||
// @TestForIssue( jiraKey = "HHH-7090" )
|
// @TestForIssue( jiraKey = "HHH-7090" )
|
||||||
// public void testSharedTransactionContextAutoJoining() {
|
// public void testSharedTransactionContextAutoJoining() {
|
||||||
// Session session = sessionFactory().openSession();
|
// Session session = scope.getSessionFactory().openSession();
|
||||||
// session.getTransaction().begin();
|
// session.getTransaction().begin();
|
||||||
//
|
//
|
||||||
// Session secondSession = session.sessionWithOptions()
|
// Session secondSession = session.sessionWithOptions()
|
||||||
|
@ -151,8 +156,8 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-7090" )
|
@TestForIssue( jiraKey = "HHH-7090" )
|
||||||
public void testSharedTransactionContextFlushBeforeCompletion() {
|
public void testSharedTransactionContextFlushBeforeCompletion(SessionFactoryScope scope) {
|
||||||
Session session = sessionFactory().openSession();
|
Session session = scope.getSessionFactory().openSession();
|
||||||
session.getTransaction().begin();
|
session.getTransaction().begin();
|
||||||
|
|
||||||
Session secondSession = session.sessionWithOptions()
|
Session secondSession = session.sessionWithOptions()
|
||||||
|
@ -174,7 +179,7 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
||||||
assertTrue( ((SessionImplementor) session).isClosed() );
|
assertTrue( ((SessionImplementor) session).isClosed() );
|
||||||
assertTrue( ((SessionImplementor) secondSession).isClosed() );
|
assertTrue( ((SessionImplementor) secondSession).isClosed() );
|
||||||
|
|
||||||
session = sessionFactory().openSession();
|
session = scope.getSessionFactory().openSession();
|
||||||
session.getTransaction().begin();
|
session.getTransaction().begin();
|
||||||
IrrelevantEntity it = (IrrelevantEntity) session.byId( IrrelevantEntity.class ).load( id );
|
IrrelevantEntity it = (IrrelevantEntity) session.byId( IrrelevantEntity.class ).load( id );
|
||||||
assertNotNull( it );
|
assertNotNull( it );
|
||||||
|
@ -185,12 +190,12 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-7239" )
|
@TestForIssue( jiraKey = "HHH-7239" )
|
||||||
public void testChildSessionCallsAfterTransactionAction() throws Exception {
|
public void testChildSessionCallsAfterTransactionAction(SessionFactoryScope scope) throws Exception {
|
||||||
Session session = openSession();
|
Session session = scope.getSessionFactory().openSession();
|
||||||
|
|
||||||
final String postCommitMessage = "post commit was called";
|
final String postCommitMessage = "post commit was called";
|
||||||
|
|
||||||
EventListenerRegistry eventListenerRegistry = sessionFactory().getServiceRegistry().getService(EventListenerRegistry.class);
|
EventListenerRegistry eventListenerRegistry = scope.getSessionFactory().getServiceRegistry().getService(EventListenerRegistry.class);
|
||||||
//register a post commit listener
|
//register a post commit listener
|
||||||
eventListenerRegistry.appendListeners(
|
eventListenerRegistry.appendListeners(
|
||||||
EventType.POST_COMMIT_INSERT,
|
EventType.POST_COMMIT_INSERT,
|
||||||
|
@ -233,8 +238,8 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-7239" )
|
@TestForIssue( jiraKey = "HHH-7239" )
|
||||||
public void testChildSessionTwoTransactions() throws Exception {
|
public void testChildSessionTwoTransactions(SessionFactoryScope scope) throws Exception {
|
||||||
Session session = openSession();
|
Session session = scope.getSessionFactory().openSession();
|
||||||
|
|
||||||
session.getTransaction().begin();
|
session.getTransaction().begin();
|
||||||
|
|
||||||
|
@ -257,11 +262,8 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-11830")
|
@TestForIssue(jiraKey = "HHH-11830")
|
||||||
public void testSharedSessionTransactionObserver() throws Exception {
|
public void testSharedSessionTransactionObserver(SessionFactoryScope scope) throws Exception {
|
||||||
Session session = openSession();
|
scope.inTransaction( session -> {
|
||||||
|
|
||||||
session.getTransaction().begin();
|
|
||||||
|
|
||||||
Field field = null;
|
Field field = null;
|
||||||
Class<?> clazz = ( (JdbcSessionOwner) session ).getTransactionCoordinator().getClass();
|
Class<?> clazz = ( (JdbcSessionOwner) session ).getTransactionCoordinator().getClass();
|
||||||
while ( clazz != null ) {
|
while ( clazz != null ) {
|
||||||
|
@ -269,16 +271,19 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
||||||
field = clazz.getDeclaredField( "observers" );
|
field = clazz.getDeclaredField( "observers" );
|
||||||
field.setAccessible( true );
|
field.setAccessible( true );
|
||||||
break;
|
break;
|
||||||
} catch (NoSuchFieldException e) {
|
}
|
||||||
|
catch (NoSuchFieldException e) {
|
||||||
clazz = clazz.getSuperclass();
|
clazz = clazz.getSuperclass();
|
||||||
} catch (Exception e) {
|
}
|
||||||
|
catch (Exception e) {
|
||||||
throw new IllegalStateException( e );
|
throw new IllegalStateException( e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertNotNull( "Observers field was not found", field );
|
assertNotNull( "Observers field was not found", field );
|
||||||
|
|
||||||
|
try {
|
||||||
//Some of these collections could be lazily initialize: check for null before invoking size()
|
//Some of these collections could be lazily initialize: check for null before invoking size()
|
||||||
final Collection collection = (Collection) field.get( ( (SessionImplementor) session ).getTransactionCoordinator() );
|
final Collection collection = (Collection) field.get( session.getTransactionCoordinator() );
|
||||||
assertTrue( collection == null || collection.size() == 0 );
|
assertTrue( collection == null || collection.size() == 0 );
|
||||||
|
|
||||||
//open secondary sessions with managed options and immediately close
|
//open secondary sessions with managed options and immediately close
|
||||||
|
@ -291,18 +296,24 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
||||||
.openSession();
|
.openSession();
|
||||||
|
|
||||||
//when the shared session is opened it should register an observer
|
//when the shared session is opened it should register an observer
|
||||||
assertEquals(1, ((Collection) field.get(((JdbcSessionOwner) session).getTransactionCoordinator())).size());
|
assertEquals(
|
||||||
|
1,
|
||||||
|
( (Collection) field.get( session.getTransactionCoordinator() ) ).size()
|
||||||
|
);
|
||||||
|
|
||||||
//observer should be released
|
//observer should be released
|
||||||
secondarySession.close();
|
secondarySession.close();
|
||||||
|
|
||||||
assertEquals(0, ((Collection) field.get(((JdbcSessionOwner) session).getTransactionCoordinator())).size());
|
assertEquals(
|
||||||
|
0,
|
||||||
|
( (Collection) field.get( session.getTransactionCoordinator() ) ).size()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new IllegalStateException( e );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
|
||||||
return new Class[] { IrrelevantEntity.class };
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -4,7 +4,9 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.stat.internal;
|
package org.hibernate.orm.test.stat.internal;
|
||||||
|
|
||||||
|
import org.hibernate.stat.internal.QueryStatisticsImpl;
|
||||||
|
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* 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.orm.test.stat.internal;
|
||||||
|
|
||||||
|
import org.hibernate.cfg.Environment;
|
||||||
|
import org.hibernate.internal.util.StringHelper;
|
||||||
|
import org.hibernate.stat.SecondLevelCacheStatistics;
|
||||||
|
import org.hibernate.stat.internal.StatisticsImpl;
|
||||||
|
|
||||||
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
|
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.hibernate.testing.orm.junit.Setting;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.hamcrest.core.Is.is;
|
||||||
|
import static org.hamcrest.core.IsNull.nullValue;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Andrea Boriero
|
||||||
|
*/
|
||||||
|
@DomainModel
|
||||||
|
@ServiceRegistry(settings = {
|
||||||
|
@Setting( name = Environment.CACHE_REGION_PREFIX, value = ConcurrentStatisticsTest.REGION_PREFIX),
|
||||||
|
@Setting( name = Environment.USE_SECOND_LEVEL_CACHE, value = "false")
|
||||||
|
})
|
||||||
|
@SessionFactory
|
||||||
|
public class ConcurrentStatisticsTest {
|
||||||
|
static final String REGION_PREFIX = "my-app";
|
||||||
|
static final String TRIVIAL_REGION_NAME = "noname";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testThatGetSecondLevelCacheStatisticsWhenSecondLevelCacheIsNotEnabledReturnsNull(SessionFactoryScope scope) {
|
||||||
|
final SecondLevelCacheStatistics secondLevelCacheStatistics = new StatisticsImpl( scope.getSessionFactory() )
|
||||||
|
.getSecondLevelCacheStatistics( StringHelper.qualify( REGION_PREFIX, TRIVIAL_REGION_NAME ) );
|
||||||
|
assertThat( secondLevelCacheStatistics, is( nullValue() ) );
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,11 +4,9 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.stat.internal;
|
package org.hibernate.orm.test.stat.internal;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
@ -17,15 +15,20 @@ import javax.persistence.NamedQuery;
|
||||||
import javax.persistence.Tuple;
|
import javax.persistence.Tuple;
|
||||||
import javax.persistence.TypedQuery;
|
import javax.persistence.TypedQuery;
|
||||||
|
|
||||||
import org.hibernate.SessionFactory;
|
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
|
||||||
import org.hibernate.stat.QueryStatistics;
|
import org.hibernate.stat.QueryStatistics;
|
||||||
import org.hibernate.stat.Statistics;
|
import org.hibernate.stat.Statistics;
|
||||||
import org.hibernate.testing.TestForIssue;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
|
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.hibernate.testing.orm.junit.Setting;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
@ -33,33 +36,24 @@ import static org.junit.Assert.assertTrue;
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
|
@DomainModel(annotatedClasses = {
|
||||||
|
QueryPlanCacheStatisticsTest.Employee.class
|
||||||
|
})
|
||||||
|
@ServiceRegistry(settings = {
|
||||||
|
@Setting( name = Environment.GENERATE_STATISTICS, value = "true")
|
||||||
|
})
|
||||||
|
@SessionFactory
|
||||||
@TestForIssue(jiraKey = "HHH-12855")
|
@TestForIssue(jiraKey = "HHH-12855")
|
||||||
public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTestCase {
|
public class QueryPlanCacheStatisticsTest {
|
||||||
|
|
||||||
private Statistics statistics;
|
private Statistics statistics;
|
||||||
|
|
||||||
@Override
|
@BeforeAll
|
||||||
public Class[] getAnnotatedClasses() {
|
protected void afterEntityManagerFactoryBuilt(SessionFactoryScope scope) {
|
||||||
return new Class[] {
|
statistics = scope.getSessionFactory().getStatistics();
|
||||||
Employee.class
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
scope.inTransaction( entityManager -> {
|
||||||
protected void addConfigOptions(Map options) {
|
|
||||||
options.put( Environment.GENERATE_STATISTICS, "true" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void afterEntityManagerFactoryBuilt() {
|
|
||||||
SessionFactory sessionFactory = entityManagerFactory().unwrap( SessionFactory.class );
|
|
||||||
statistics = sessionFactory.getStatistics();
|
|
||||||
|
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
|
||||||
for ( long i = 1; i <= 5; i++ ) {
|
for ( long i = 1; i <= 5; i++ ) {
|
||||||
if ( i % 3 == 0 ) {
|
|
||||||
entityManager.flush();
|
|
||||||
}
|
|
||||||
Employee employee = new Employee();
|
Employee employee = new Employee();
|
||||||
employee.setName( String.format( "Employee: %d", i ) );
|
employee.setName( String.format( "Employee: %d", i ) );
|
||||||
entityManager.persist( employee );
|
entityManager.persist( employee );
|
||||||
|
@ -67,14 +61,18 @@ public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTes
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@BeforeEach
|
||||||
public void test() {
|
protected void cleanup(SessionFactoryScope scope) {
|
||||||
|
scope.getSessionFactory().getQueryEngine().getInterpretationCache().close();
|
||||||
statistics.clear();
|
statistics.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test(SessionFactoryScope scope) {
|
||||||
assertEquals( 0, statistics.getQueryPlanCacheHitCount() );
|
assertEquals( 0, statistics.getQueryPlanCacheHitCount() );
|
||||||
assertEquals( 0, statistics.getQueryPlanCacheMissCount() );
|
assertEquals( 0, statistics.getQueryPlanCacheMissCount() );
|
||||||
|
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
scope.inTransaction( entityManager -> {
|
||||||
final String FIRST_QUERY = "select e from Employee e";
|
final String FIRST_QUERY = "select e from Employee e";
|
||||||
|
|
||||||
entityManager.createQuery( FIRST_QUERY );
|
entityManager.createQuery( FIRST_QUERY );
|
||||||
|
@ -125,10 +123,8 @@ public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTes
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-13077" )
|
@TestForIssue( jiraKey = "HHH-13077" )
|
||||||
public void testCreateQueryHitCount() {
|
public void testCreateQueryHitCount(SessionFactoryScope scope) {
|
||||||
statistics.clear();
|
scope.inTransaction( entityManager -> {
|
||||||
|
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
|
||||||
|
|
||||||
List<Employee> employees = entityManager.createQuery(
|
List<Employee> employees = entityManager.createQuery(
|
||||||
"select e from Employee e", Employee.class )
|
"select e from Employee e", Employee.class )
|
||||||
|
@ -142,7 +138,7 @@ public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTes
|
||||||
assertEquals( 0, statistics.getQueryPlanCacheHitCount() );
|
assertEquals( 0, statistics.getQueryPlanCacheHitCount() );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
scope.inTransaction( entityManager -> {
|
||||||
|
|
||||||
List<Employee> employees = entityManager.createQuery(
|
List<Employee> employees = entityManager.createQuery(
|
||||||
"select e from Employee e", Employee.class )
|
"select e from Employee e", Employee.class )
|
||||||
|
@ -156,7 +152,7 @@ public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTes
|
||||||
assertEquals( 1, statistics.getQueryPlanCacheHitCount() );
|
assertEquals( 1, statistics.getQueryPlanCacheHitCount() );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
scope.inTransaction( entityManager -> {
|
||||||
|
|
||||||
List<Employee> employees = entityManager.createQuery(
|
List<Employee> employees = entityManager.createQuery(
|
||||||
"select e from Employee e", Employee.class )
|
"select e from Employee e", Employee.class )
|
||||||
|
@ -173,12 +169,11 @@ public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTes
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-13077" )
|
@TestForIssue( jiraKey = "HHH-13077" )
|
||||||
public void testCreateNamedQueryHitCount() {
|
public void testCreateNamedQueryHitCount(SessionFactoryScope scope) {
|
||||||
//This is for the NamedQuery that gets compiled
|
// Compile the named queries
|
||||||
assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
|
scope.getSessionFactory().getQueryEngine().getNamedObjectRepository().checkNamedQueries( scope.getSessionFactory().getQueryEngine() );
|
||||||
statistics.clear();
|
statistics.clear();
|
||||||
|
scope.inTransaction( entityManager -> {
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
|
||||||
|
|
||||||
Employee employees = entityManager.createNamedQuery(
|
Employee employees = entityManager.createNamedQuery(
|
||||||
"find_employee_by_name", Employee.class )
|
"find_employee_by_name", Employee.class )
|
||||||
|
@ -191,7 +186,7 @@ public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTes
|
||||||
assertEquals( 1, statistics.getQueryPlanCacheHitCount() );
|
assertEquals( 1, statistics.getQueryPlanCacheHitCount() );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
scope.inTransaction( entityManager -> {
|
||||||
|
|
||||||
Employee employees = entityManager.createNamedQuery(
|
Employee employees = entityManager.createNamedQuery(
|
||||||
"find_employee_by_name", Employee.class )
|
"find_employee_by_name", Employee.class )
|
||||||
|
@ -207,10 +202,8 @@ public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTes
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-13077" )
|
@TestForIssue( jiraKey = "HHH-13077" )
|
||||||
public void testCreateQueryTupleHitCount() {
|
public void testCreateQueryTupleHitCount(SessionFactoryScope scope) {
|
||||||
statistics.clear();
|
scope.inTransaction( entityManager -> {
|
||||||
|
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
|
||||||
|
|
||||||
List<Tuple> employees = entityManager.createQuery(
|
List<Tuple> employees = entityManager.createQuery(
|
||||||
"select e.id, e.name from Employee e", Tuple.class )
|
"select e.id, e.name from Employee e", Tuple.class )
|
||||||
|
@ -224,7 +217,7 @@ public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTes
|
||||||
assertEquals( 0, statistics.getQueryPlanCacheHitCount() );
|
assertEquals( 0, statistics.getQueryPlanCacheHitCount() );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
scope.inTransaction( entityManager -> {
|
||||||
|
|
||||||
List<Tuple> employees = entityManager.createQuery(
|
List<Tuple> employees = entityManager.createQuery(
|
||||||
"select e.id, e.name from Employee e", Tuple.class )
|
"select e.id, e.name from Employee e", Tuple.class )
|
||||||
|
@ -238,7 +231,7 @@ public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTes
|
||||||
assertEquals( 1, statistics.getQueryPlanCacheHitCount() );
|
assertEquals( 1, statistics.getQueryPlanCacheHitCount() );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
scope.inTransaction( entityManager -> {
|
||||||
|
|
||||||
List<Tuple> employees = entityManager.createQuery(
|
List<Tuple> employees = entityManager.createQuery(
|
||||||
"select e.id, e.name from Employee e", Tuple.class )
|
"select e.id, e.name from Employee e", Tuple.class )
|
||||||
|
@ -255,10 +248,8 @@ public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTes
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-13077")
|
@TestForIssue(jiraKey = "HHH-13077")
|
||||||
public void testLockModeHitCount() {
|
public void testLockModeHitCount(SessionFactoryScope scope) {
|
||||||
statistics.clear();
|
scope.inTransaction( entityManager -> {
|
||||||
|
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
|
||||||
TypedQuery<Employee> typedQuery = entityManager.createQuery( "select e from Employee e", Employee.class );
|
TypedQuery<Employee> typedQuery = entityManager.createQuery( "select e from Employee e", Employee.class );
|
||||||
|
|
||||||
List<Employee> employees = typedQuery.getResultList();
|
List<Employee> employees = typedQuery.getResultList();
|
|
@ -4,7 +4,9 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.stat.internal;
|
package org.hibernate.orm.test.stat.internal;
|
||||||
|
|
||||||
|
import org.hibernate.stat.internal.StatsNamedContainer;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
|
@ -1,45 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.persister.entity;
|
|
||||||
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.hibernate.cfg.Configuration;
|
|
||||||
import org.hibernate.dialect.H2Dialect;
|
|
||||||
|
|
||||||
import org.hibernate.testing.RequiresDialect;
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
@RequiresDialect(H2Dialect.class)
|
|
||||||
public class FormulaTemplateSchemaSubstitutionTest extends AbstractSchemaSubstitutionFormulaTest {
|
|
||||||
|
|
||||||
private static final String CUSTOM_SCHEMA = "CUSTOM_SCHEMA";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure(Configuration configuration) {
|
|
||||||
final Properties properties = new Properties();
|
|
||||||
properties.put( "hibernate.default_schema", CUSTOM_SCHEMA );
|
|
||||||
configuration.addProperties( properties );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String createSecondSchema() {
|
|
||||||
return CUSTOM_SCHEMA;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void validate(String formula) {
|
|
||||||
assertEquals( "Formula should not contain {} characters",
|
|
||||||
4, formula.split( CUSTOM_SCHEMA + ".", -1 ).length - 1
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
package org.hibernate.procedure.internal;
|
|
||||||
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.Query;
|
|
||||||
import org.hibernate.dialect.H2Dialect;
|
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
|
||||||
import org.hibernate.testing.RequiresDialect;
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Nathan Xu
|
|
||||||
*/
|
|
||||||
public class ProcedureCallImplTest extends BaseEntityManagerFunctionalTestCase {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@TestForIssue( jiraKey = "HHH-13644" )
|
|
||||||
@RequiresDialect( H2Dialect.class )
|
|
||||||
public void testNoNullPointerExceptionThrown() {
|
|
||||||
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
|
||||||
|
|
||||||
em.getTransaction().begin();
|
|
||||||
|
|
||||||
em.createNativeQuery("CREATE ALIAS GET_RANDOM_VALUE FOR \"java.lang.Math.random\";").executeUpdate();
|
|
||||||
|
|
||||||
Query query = em.createStoredProcedureQuery("GET_RANDOM_VALUE");
|
|
||||||
|
|
||||||
Stream stream = query.getResultStream();
|
|
||||||
|
|
||||||
Assert.assertEquals(1, stream.count());
|
|
||||||
|
|
||||||
em.getTransaction().commit();
|
|
||||||
|
|
||||||
em.close();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,55 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.property;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.hibernate.Hibernate;
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.Transaction;
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Michael Rudolf
|
|
||||||
*/
|
|
||||||
public class DirectPropertyAccessorTest extends BaseCoreFunctionalTestCase {
|
|
||||||
@Test
|
|
||||||
@TestForIssue( jiraKey="HHH-3718" )
|
|
||||||
public void testDirectIdPropertyAccess() throws Exception {
|
|
||||||
Session s = openSession();
|
|
||||||
final Transaction transaction = s.beginTransaction();
|
|
||||||
Item i = new Item();
|
|
||||||
s.persist( i );
|
|
||||||
Order o = new Order();
|
|
||||||
o.setOrderNumber( 1 );
|
|
||||||
o.getItems().add( i );
|
|
||||||
s.persist( o );
|
|
||||||
transaction.commit();
|
|
||||||
s.clear();
|
|
||||||
|
|
||||||
o = ( Order ) s.load( Order.class, 1 );
|
|
||||||
assertFalse( Hibernate.isInitialized( o ) );
|
|
||||||
o.getOrderNumber();
|
|
||||||
// If you mapped with field access, any method, except id, call initializes the proxy
|
|
||||||
assertFalse( Hibernate.isInitialized( o ) );
|
|
||||||
o.getName();
|
|
||||||
assertTrue( Hibernate.isInitialized( o ) );
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
|
||||||
return new Class<?>[] {
|
|
||||||
Order.class,
|
|
||||||
Item.class,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.stat.internal;
|
|
||||||
|
|
||||||
import org.hibernate.SessionFactory;
|
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
|
||||||
import org.hibernate.cfg.Configuration;
|
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|
||||||
import org.hibernate.internal.util.StringHelper;
|
|
||||||
import org.hibernate.stat.SecondLevelCacheStatistics;
|
|
||||||
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.hamcrest.core.Is.is;
|
|
||||||
import static org.hamcrest.core.IsNull.nullValue;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Andrea Boriero
|
|
||||||
*/
|
|
||||||
public class ConcurrentStatisticsTest extends BaseCoreFunctionalTestCase {
|
|
||||||
private static final String REGION_PREFIX = "my-app";
|
|
||||||
private static final String TRIVIAL_REGION_NAME = "noname";
|
|
||||||
|
|
||||||
private StatisticsImpl statistics;
|
|
||||||
private SessionFactory sessionFactory;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
sessionFactory = sessionFactory();
|
|
||||||
statistics = new StatisticsImpl( (SessionFactoryImplementor) sessionFactory );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure(Configuration configuration) {
|
|
||||||
super.configure( configuration );
|
|
||||||
configuration.setProperty( AvailableSettings.CACHE_REGION_PREFIX, REGION_PREFIX );
|
|
||||||
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
sessionFactory.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testThatGetSecondLevelCacheStatisticsWhenSecondLevelCacheIsNotEnabledReturnsNull() {
|
|
||||||
final SecondLevelCacheStatistics secondLevelCacheStatistics = statistics
|
|
||||||
.getSecondLevelCacheStatistics( StringHelper.qualify( REGION_PREFIX, TRIVIAL_REGION_NAME ) );
|
|
||||||
assertThat( secondLevelCacheStatistics, is( nullValue() ) );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,7 +6,7 @@
|
||||||
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
-->
|
-->
|
||||||
<hibernate-mapping xmlns="http://www.hibernate.org/xsd/hibernate-mapping">
|
<hibernate-mapping xmlns="http://www.hibernate.org/xsd/hibernate-mapping">
|
||||||
<class name="org.hibernate.property.GetAndIsVariantGetterTest$TheEntity">
|
<class name="org.hibernate.orm.test.property.GetAndIsVariantGetterTest$TheEntity">
|
||||||
<id name="id"/>
|
<id name="id"/>
|
||||||
</class>
|
</class>
|
||||||
</hibernate-mapping>
|
</hibernate-mapping>
|
|
@ -35,11 +35,6 @@ dependencies {
|
||||||
testRuntime( libraries.log4j )
|
testRuntime( libraries.log4j )
|
||||||
}
|
}
|
||||||
|
|
||||||
// resources inherently exclude sources
|
|
||||||
sourceSets.test.resources {
|
|
||||||
setSrcDirs( ['src/test/java'] )
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo : Fold into hibernate-core and publish in separate publications
|
// todo : Fold into hibernate-core and publish in separate publications
|
||||||
// once http://issues.gradle.org/browse/GRADLE-2966 is resolved;
|
// once http://issues.gradle.org/browse/GRADLE-2966 is resolved;
|
||||||
// that will allow us to keep the same artifactId and publish the pom
|
// that will allow us to keep the same artifactId and publish the pom
|
||||||
|
|
|
@ -6,11 +6,8 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.testing.annotations;
|
package org.hibernate.testing.annotations;
|
||||||
|
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
|
||||||
|
|
||||||
import org.hibernate.testing.orm.junit.Jpa;
|
|
||||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||||
import org.hibernate.testing.orm.junit.Setting;
|
import org.hibernate.testing.orm.junit.Jpa;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
@ -19,16 +16,7 @@ import static org.hamcrest.Matchers.notNullValue;
|
||||||
@Jpa(
|
@Jpa(
|
||||||
annotatedClasses = {
|
annotatedClasses = {
|
||||||
AnEntity.class
|
AnEntity.class
|
||||||
},
|
|
||||||
properties = {
|
|
||||||
@Setting( name = AvailableSettings.JPA_JDBC_URL, value = "jdbc:h2:mem:test_db" ),
|
|
||||||
@Setting( name = AvailableSettings.JPA_JDBC_USER, value = "tester" )
|
|
||||||
}
|
}
|
||||||
// works with either
|
|
||||||
// integrationSettings = {
|
|
||||||
// @Setting( name = AvailableSettings.JPA_JDBC_URL, value = "jdbc:h2:mem:test_db" ),
|
|
||||||
// @Setting( name = AvailableSettings.JPA_JDBC_USER, value = "tester" )
|
|
||||||
// }
|
|
||||||
)
|
)
|
||||||
public class BasicEntityManagerFactoryScopeTests {
|
public class BasicEntityManagerFactoryScopeTests {
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -6,19 +6,18 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.testing.annotations;
|
package org.hibernate.testing.annotations;
|
||||||
|
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.dialect.H2Dialect;
|
||||||
|
|
||||||
import org.hibernate.testing.orm.junit.DomainModel;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
import org.hibernate.testing.orm.junit.Setting;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
|
|
||||||
@ServiceRegistry( settings = @Setting( name = AvailableSettings.URL, value = "jdbc:h2:mem:test_db" ) )
|
@RequiresDialect(H2Dialect.class)
|
||||||
@DomainModel( annotatedClasses = AnEntity.class )
|
@DomainModel( annotatedClasses = AnEntity.class )
|
||||||
@SessionFactory
|
@SessionFactory
|
||||||
public class BasicSessionFactoryScopeTests {
|
public class BasicSessionFactoryScopeTests {
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
#
|
||||||
|
# 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>.
|
||||||
|
#
|
||||||
|
|
||||||
|
hibernate.dialect @db.dialect@
|
||||||
|
hibernate.connection.driver_class @jdbc.driver@
|
||||||
|
hibernate.connection.url @jdbc.url@
|
||||||
|
hibernate.connection.username @jdbc.user@
|
||||||
|
hibernate.connection.password @jdbc.pass@
|
||||||
|
|
||||||
|
hibernate.connection.pool_size 5
|
||||||
|
|
||||||
|
hibernate.show_sql false
|
||||||
|
hibernate.format_sql true
|
||||||
|
|
||||||
|
hibernate.max_fetch_depth 5
|
||||||
|
|
||||||
|
hibernate.cache.region_prefix hibernate.test
|
||||||
|
hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
|
||||||
|
|
||||||
|
javax.persistence.validation.mode=NONE
|
||||||
|
hibernate.service.allow_crawling=false
|
||||||
|
hibernate.session.events.log=true
|
||||||
|
hibernate.hql.bulk_id_strategy.global_temporary.drop_tables=true
|
Loading…
Reference in New Issue