HHH-9761 - Make native APIs typed;

HHH-9790 - Remove deprecated methods from Session and SessionFactory
This commit is contained in:
Steve Ebersole 2015-05-12 22:56:37 -05:00
parent dc0f77a236
commit 288f490418
30 changed files with 719 additions and 373 deletions

View File

@ -147,51 +147,53 @@ class HibernateBuildPlugin implements Plugin<Project> {
}
if ( javaTargetExtension.version.java8Compatible ) {
javaCompileTask.options.compilerArgs += [
"-source", '1.8',
"-target", '1.8'
]
}
else {
javaCompileTask.options.compilerArgs += [
"-source", '1.6',
"-target", '1.6'
]
if ( sourceSet.name == 'main' ) {
if ( javaTargetExtension.version.java8Compatible ) {
javaCompileTask.options.compilerArgs += [
"-source", '1.8',
"-target", '1.8'
]
}
else {
javaCompileTask.options.compilerArgs += [
"-source", '1.6',
"-target", '1.6'
]
if ( java6Home != null ) {
if ( javaTargetExtension.shouldApplyTargetToCompile ) {
// Technically we need only one here between:
// 1) setting the javac executable
// 2) setting the bootClasspath
// However, (1) requires fork=true whereas (2) does not.
// javaCompileTask.options.fork = true
// javaCompileTask.options.forkOptions.executable = java6Home.javacExecutable
javaCompileTask.options.bootClasspath = java6Home.runtimeJar.absolutePath
if ( java6Home != null ) {
if ( javaTargetExtension.shouldApplyTargetToCompile ) {
// Technically we need only one here between:
// 1) setting the javac executable
// 2) setting the bootClasspath
// However, (1) requires fork=true whereas (2) does not.
// javaCompileTask.options.fork = true
// javaCompileTask.options.forkOptions.executable = java6Home.javacExecutable
javaCompileTask.options.bootClasspath = java6Home.runtimeJar.absolutePath
}
}
}
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Apply to test compile task
SourceSet testSourceSet = project.getConvention().findPlugin( JavaPluginConvention.class ).sourceSets.findByName( "test" )
JavaCompile compileTestTask = project.tasks.findByName( testSourceSet.compileJavaTaskName ) as JavaCompile
// NOTE : see the note abovewrt aptDir
File testAptDir = project.file( "${project.buildDir}/generated-src/apt/test" )
testSourceSet.allJava.srcDir( testAptDir )
compileTestTask.options.compilerArgs += [
"-nowarn",
"-encoding", "UTF-8",
"-s", "${testAptDir.absolutePath}"
]
compileTestTask.doFirst {
testAptDir.mkdirs()
}
//
//
// // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// // Apply to test compile task
//
// SourceSet testSourceSet = project.getConvention().findPlugin( JavaPluginConvention.class ).sourceSets.findByName( "test" )
// JavaCompile compileTestTask = project.tasks.findByName( testSourceSet.compileJavaTaskName ) as JavaCompile
//
// // NOTE : see the note above wrt aptDir
// File testAptDir = project.file( "${project.buildDir}/generated-src/apt/test" )
// testSourceSet.allJava.srcDir( testAptDir )
//
// compileTestTask.options.compilerArgs += [
// "-nowarn",
// "-encoding", "UTF-8",
// "-s", "${testAptDir.absolutePath}"
// ]
// compileTestTask.doFirst {
// testAptDir.mkdirs()
// }
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Apply to test tasks

View File

@ -31,7 +31,7 @@ import java.io.Serializable;
* @author Eric Dalquist
* @author Steve Ebersole
*/
public interface IdentifierLoadAccess {
public interface IdentifierLoadAccess<T> {
/**
* Specify the {@link LockOptions} to use when retrieving the entity.
*
@ -39,7 +39,7 @@ public interface IdentifierLoadAccess {
*
* @return {@code this}, for method chaining
*/
public IdentifierLoadAccess with(LockOptions lockOptions);
public IdentifierLoadAccess<T> with(LockOptions lockOptions);
/**
* Return the persistent instance with the given identifier, assuming that the instance exists. This method
@ -53,7 +53,7 @@ public interface IdentifierLoadAccess {
*
* @return the persistent instance or proxy
*/
public Object getReference(Serializable id);
public T getReference(Serializable id);
/**
* Return the persistent instance with the given identifier, or null if there is no such persistent instance.
@ -64,5 +64,5 @@ public interface IdentifierLoadAccess {
*
* @return The persistent instance or {@code null}
*/
public Object load(Serializable id);
public T load(Serializable id);
}

View File

@ -31,7 +31,7 @@ package org.hibernate;
*
* @see org.hibernate.annotations.NaturalId
*/
public interface NaturalIdLoadAccess {
public interface NaturalIdLoadAccess<T> {
/**
* Specify the {@link LockOptions} to use when retrieving the entity.
*
@ -39,7 +39,7 @@ public interface NaturalIdLoadAccess {
*
* @return {@code this}, for method chaining
*/
public NaturalIdLoadAccess with(LockOptions lockOptions);
public NaturalIdLoadAccess<T> with(LockOptions lockOptions);
/**
* Add a NaturalId attribute value.
@ -49,7 +49,7 @@ public interface NaturalIdLoadAccess {
*
* @return {@code this}, for method chaining
*/
public NaturalIdLoadAccess using(String attributeName, Object value);
public NaturalIdLoadAccess<T> using(String attributeName, Object value);
/**
* For entities with mutable natural ids, should Hibernate perform "synchronization" prior to performing
@ -67,7 +67,7 @@ public interface NaturalIdLoadAccess {
*
* @return {@code this}, for method chaining
*/
public NaturalIdLoadAccess setSynchronizationEnabled(boolean enabled);
public NaturalIdLoadAccess<T> setSynchronizationEnabled(boolean enabled);
/**
* Return the persistent instance with the natural id value(s) defined by the call(s) to {@link #using}. This
@ -79,7 +79,7 @@ public interface NaturalIdLoadAccess {
*
* @return the persistent instance or proxy
*/
public Object getReference();
public T getReference();
/**
* Return the persistent instance with the natural id value(s) defined by the call(s) to {@link #using}, or
@ -88,6 +88,6 @@ public interface NaturalIdLoadAccess {
*
* @return The persistent instance or {@code null}
*/
public Object load();
public T load();
}

View File

@ -275,6 +275,8 @@ public interface Session extends SharedSessionContract, java.io.Closeable {
/**
* Return the persistent instance of the given entity class with the given identifier,
* obtaining the specified lock mode, assuming the instance exists.
* <p/>
* Convenient form of {@link #load(Class, Serializable, LockOptions)}
*
* @param theClass a persistent class
* @param id a valid identifier of an existing persistent instance of the class
@ -282,10 +284,9 @@ public interface Session extends SharedSessionContract, java.io.Closeable {
*
* @return the persistent instance or proxy
*
* @deprecated LockMode parameter should be replaced with LockOptions
* @see #load(Class, Serializable, LockOptions)
*/
@Deprecated
public Object load(Class theClass, Serializable id, LockMode lockMode);
public <T> T load(Class<T> theClass, Serializable id, LockMode lockMode);
/**
* Return the persistent instance of the given entity class with the given identifier,
@ -296,11 +297,13 @@ public interface Session extends SharedSessionContract, java.io.Closeable {
* @param lockOptions contains the lock level
* @return the persistent instance or proxy
*/
public Object load(Class theClass, Serializable id, LockOptions lockOptions);
public <T> T load(Class<T> theClass, Serializable id, LockOptions lockOptions);
/**
* Return the persistent instance of the given entity class with the given identifier,
* obtaining the specified lock mode, assuming the instance exists.
* <p/>
* Convenient form of {@link #load(String, Serializable, LockOptions)}
*
* @param entityName a persistent class
* @param id a valid identifier of an existing persistent instance of the class
@ -308,9 +311,8 @@ public interface Session extends SharedSessionContract, java.io.Closeable {
*
* @return the persistent instance or proxy
*
* @deprecated LockMode parameter should be replaced with LockOptions
* @see #load(String, Serializable, LockOptions)
*/
@Deprecated
public Object load(String entityName, Serializable id, LockMode lockMode);
/**
@ -339,7 +341,7 @@ public interface Session extends SharedSessionContract, java.io.Closeable {
*
* @return the persistent instance or proxy
*/
public Object load(Class theClass, Serializable id);
public <T> T load(Class<T> theClass, Serializable id);
/**
* Return the persistent instance of the given entity class with the given identifier,
@ -548,13 +550,15 @@ public interface Session extends SharedSessionContract, java.io.Closeable {
* lock (<tt>LockMode.PESSIMISTIC_WRITE</tt>), or to simply reassociate a transient instance
* with a session (<tt>LockMode.NONE</tt>). This operation cascades to associated
* instances if the association is mapped with <tt>cascade="lock"</tt>.
* <p/>
* Convenient form of {@link LockRequest#lock(Object)} via {@link #buildLockRequest(LockOptions)}
*
* @param object a persistent or transient instance
* @param lockMode the lock level
*
* @deprecated instead call buildLockRequest(LockMode).lock(object)
* @see #buildLockRequest(LockOptions)
* @see LockRequest#lock(Object)
*/
@Deprecated
public void lock(Object object, LockMode lockMode);
/**
@ -563,15 +567,16 @@ public interface Session extends SharedSessionContract, java.io.Closeable {
* lock (<tt>LockMode.PESSIMISTIC_WRITE</tt>), or to simply reassociate a transient instance
* with a session (<tt>LockMode.NONE</tt>). This operation cascades to associated
* instances if the association is mapped with <tt>cascade="lock"</tt>.
* <p/>
* Convenient form of {@link LockRequest#lock(String, Object)} via {@link #buildLockRequest(LockOptions)}
*
* @param entityName The name of the entity
* @param object a persistent or transient instance
* @param lockMode the lock level
*
* @deprecated instead call buildLockRequest(LockMode).lock(entityName, object)
* @see #buildLockRequest(LockOptions)
* @see LockRequest#lock(String, Object)
*/
@SuppressWarnings( {"JavaDoc"})
@Deprecated
public void lock(String entityName, Object object, LockMode lockMode);
/**
@ -624,13 +629,14 @@ public interface Session extends SharedSessionContract, java.io.Closeable {
* the given <tt>LockMode</tt>. It is inadvisable to use this to implement
* long-running sessions that span many business tasks. This method is, however,
* useful in certain special circumstances.
* <p/>
* Convenient form of {@link #refresh(Object, LockOptions)}
*
* @param object a persistent or detached instance
* @param lockMode the lock mode to use
*
* @deprecated LockMode parameter should be replaced with LockOptions
* @see #refresh(Object, LockOptions)
*/
@Deprecated
public void refresh(Object object, LockMode lockMode);
/**
@ -689,29 +695,30 @@ public interface Session extends SharedSessionContract, java.io.Closeable {
* or null if there is no such persistent instance. (If the instance is already associated
* with the session, return that instance. This method never returns an uninitialized instance.)
*
* @param clazz a persistent class
* @param entityType The entity type
* @param id an identifier
*
* @return a persistent instance or null
*/
public Object get(Class clazz, Serializable id);
public <T> T get(Class<T> entityType, Serializable id);
/**
* Return the persistent instance of the given entity class with the given identifier,
* or null if there is no such persistent instance. (If the instance is already associated
* with the session, return that instance. This method never returns an uninitialized instance.)
* Obtain the specified lock mode if the instance exists.
* <p/>
* Convenient form of {@link #get(Class, Serializable, LockOptions)}
*
* @param clazz a persistent class
* @param entityType The entity type
* @param id an identifier
* @param lockMode the lock mode
*
* @return a persistent instance or null
*
* @deprecated LockMode parameter should be replaced with LockOptions
* @see #get(Class, Serializable, LockOptions)
*/
@Deprecated
public Object get(Class clazz, Serializable id, LockMode lockMode);
public <T> T get(Class<T> entityType, Serializable id, LockMode lockMode);
/**
* Return the persistent instance of the given entity class with the given identifier,
@ -719,13 +726,13 @@ public interface Session extends SharedSessionContract, java.io.Closeable {
* with the session, return that instance. This method never returns an uninitialized instance.)
* Obtain the specified lock mode if the instance exists.
*
* @param clazz a persistent class
* @param entityType The entity type
* @param id an identifier
* @param lockOptions the lock mode
*
* @return a persistent instance or null
*/
public Object get(Class clazz, Serializable id, LockOptions lockOptions);
public <T> T get(Class<T> entityType, Serializable id, LockOptions lockOptions);
/**
* Return the persistent instance of the given named entity with the given identifier,
@ -744,6 +751,8 @@ public interface Session extends SharedSessionContract, java.io.Closeable {
* or null if there is no such persistent instance. (If the instance is already associated
* with the session, return that instance. This method never returns an uninitialized instance.)
* Obtain the specified lock mode if the instance exists.
* <p/>
* Convenient form of {@link #get(String, Serializable, LockOptions)}
*
* @param entityName the entity name
* @param id an identifier
@ -751,9 +760,8 @@ public interface Session extends SharedSessionContract, java.io.Closeable {
*
* @return a persistent instance or null
*
* @deprecated LockMode parameter should be replaced with LockOptions
* @see #get(String, Serializable, LockOptions)
*/
@Deprecated
public Object get(String entityName, Serializable id, LockMode lockMode);
/**
@ -801,7 +809,7 @@ public interface Session extends SharedSessionContract, java.io.Closeable {
*
* @throws HibernateException If the specified Class cannot be resolved as a mapped entity
*/
public IdentifierLoadAccess byId(Class entityClass);
public <T> IdentifierLoadAccess<T> byId(Class<T> entityClass);
/**
* Create an {@link NaturalIdLoadAccess} instance to retrieve the specified entity by
@ -825,7 +833,7 @@ public interface Session extends SharedSessionContract, java.io.Closeable {
*
* @throws HibernateException If the specified Class cannot be resolved as a mapped entity
*/
public NaturalIdLoadAccess byNaturalId(Class entityClass);
public <T> NaturalIdLoadAccess<T> byNaturalId(Class<T> entityClass);
/**
* Create an {@link SimpleNaturalIdLoadAccess} instance to retrieve the specified entity by
@ -851,7 +859,7 @@ public interface Session extends SharedSessionContract, java.io.Closeable {
* @throws HibernateException If the specified entityClass cannot be resolved as a mapped entity, or if the
* entity does not define a natural-id or if its natural-id is made up of multiple attributes.
*/
public SimpleNaturalIdLoadAccess bySimpleNaturalId(Class entityClass);
public <T> SimpleNaturalIdLoadAccess<T> bySimpleNaturalId(Class<T> entityClass);
/**
* Enable the named filter for this current session.

View File

@ -32,7 +32,7 @@ package org.hibernate;
* @see org.hibernate.annotations.NaturalId
* @see NaturalIdLoadAccess
*/
public interface SimpleNaturalIdLoadAccess {
public interface SimpleNaturalIdLoadAccess<T> {
/**
* Specify the {@link org.hibernate.LockOptions} to use when retrieving the entity.
*
@ -40,7 +40,7 @@ public interface SimpleNaturalIdLoadAccess {
*
* @return {@code this}, for method chaining
*/
public SimpleNaturalIdLoadAccess with(LockOptions lockOptions);
public SimpleNaturalIdLoadAccess<T> with(LockOptions lockOptions);
/**
* For entities with mutable natural ids, should Hibernate perform "synchronization" prior to performing
@ -53,7 +53,7 @@ public interface SimpleNaturalIdLoadAccess {
*
* @return {@code this}, for method chaining
*/
public SimpleNaturalIdLoadAccess setSynchronizationEnabled(boolean enabled);
public SimpleNaturalIdLoadAccess<T> setSynchronizationEnabled(boolean enabled);
/**
* Return the persistent instance with the given natural id value, assuming that the instance exists. This method
@ -67,7 +67,7 @@ public interface SimpleNaturalIdLoadAccess {
*
* @return The persistent instance or proxy, if an instance exists. Otherwise, {@code null}.
*/
public Object getReference(Object naturalIdValue);
public T getReference(Object naturalIdValue);
/**
* Return the persistent instance with the given natural id value, or {@code null} if there is no such persistent
@ -78,6 +78,6 @@ public interface SimpleNaturalIdLoadAccess {
*
* @return The persistent instance or {@code null}
*/
public Object load(Object naturalIdValue);
public T load(Object naturalIdValue);
}

View File

@ -304,7 +304,7 @@ public class CollectionLoadContext {
LOG.debugf( "Caching collection: %s", MessageHelper.collectionInfoString( persister, lce.getCollection(), lce.getKey(), session ) );
}
if ( !session.getEnabledFilters().isEmpty() && persister.isAffectedByEnabledFilters( session ) ) {
if ( !session.getLoadQueryInfluencers().getEnabledFilters().isEmpty() && persister.isAffectedByEnabledFilters( session ) ) {
// some filters affecting the collection are enabled on the session, so do not do the put into the cache.
if ( debugEnabled ) {
LOG.debug( "Refusing to add to cache due to enabled filters" );

View File

@ -27,7 +27,6 @@ import java.io.Serializable;
import java.sql.Connection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.hibernate.CacheMode;
import org.hibernate.Criteria;
@ -250,21 +249,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor, Session {
return sessionImplementor.scroll( spec, queryParameters );
}
@Override
public Object getFilterParameterValue(String filterParameterName) {
return sessionImplementor.getFilterParameterValue( filterParameterName );
}
@Override
public Type getFilterParameterType(String filterParameterName) {
return sessionImplementor.getFilterParameterType( filterParameterName );
}
@Override
public Map getEnabledFilters() {
return sessionImplementor.getEnabledFilters();
}
@Override
public int getDontFlushFromFind() {
return sessionImplementor.getDontFlushFromFind();
@ -345,16 +329,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor, Session {
sessionImplementor.afterScrollOperation();
}
@Override
public String getFetchProfile() {
return sessionImplementor.getFetchProfile();
}
@Override
public void setFetchProfile(String name) {
sessionImplementor.setFetchProfile( name );
}
@Override
public TransactionCoordinator getTransactionCoordinator() {
return sessionImplementor.getTransactionCoordinator();
@ -513,12 +487,12 @@ public class SessionDelegatorBaseImpl implements SessionImplementor, Session {
}
@Override
public Object load(Class theClass, Serializable id, LockMode lockMode) {
public <T> T load(Class<T> theClass, Serializable id, LockMode lockMode) {
return session.load( theClass, id, lockMode );
}
@Override
public Object load(Class theClass, Serializable id, LockOptions lockOptions) {
public <T> T load(Class<T> theClass, Serializable id, LockOptions lockOptions) {
return session.load( theClass, id, lockOptions );
}
@ -533,7 +507,7 @@ public class SessionDelegatorBaseImpl implements SessionImplementor, Session {
}
@Override
public Object load(Class theClass, Serializable id) {
public <T> T load(Class<T> theClass, Serializable id) {
return session.load( theClass, id );
}
@ -673,18 +647,18 @@ public class SessionDelegatorBaseImpl implements SessionImplementor, Session {
}
@Override
public Object get(Class clazz, Serializable id) {
return session.get( clazz, id );
public <T> T get(Class<T> theClass, Serializable id) {
return session.get( theClass, id );
}
@Override
public Object get(Class clazz, Serializable id, LockMode lockMode) {
return session.get( clazz, id, lockMode );
public <T> T get(Class<T> theClass, Serializable id, LockMode lockMode) {
return session.get( theClass, id, lockMode );
}
@Override
public Object get(Class clazz, Serializable id, LockOptions lockOptions) {
return session.get( clazz, id, lockOptions );
public <T> T get(Class<T> theClass, Serializable id, LockOptions lockOptions) {
return session.get( theClass, id, lockOptions );
}
@Override
@ -713,7 +687,7 @@ public class SessionDelegatorBaseImpl implements SessionImplementor, Session {
}
@Override
public IdentifierLoadAccess byId(Class entityClass) {
public <T> IdentifierLoadAccess<T> byId(Class<T> entityClass) {
return session.byId( entityClass );
}
@ -723,7 +697,7 @@ public class SessionDelegatorBaseImpl implements SessionImplementor, Session {
}
@Override
public NaturalIdLoadAccess byNaturalId(Class entityClass) {
public <T> NaturalIdLoadAccess<T> byNaturalId(Class<T> entityClass) {
return session.byNaturalId( entityClass );
}
@ -733,7 +707,7 @@ public class SessionDelegatorBaseImpl implements SessionImplementor, Session {
}
@Override
public SimpleNaturalIdLoadAccess bySimpleNaturalId(Class entityClass) {
public <T> SimpleNaturalIdLoadAccess<T> bySimpleNaturalId(Class<T> entityClass) {
return session.bySimpleNaturalId( entityClass );
}

View File

@ -295,4 +295,28 @@ public interface SessionFactoryImplementor extends Mapping, SessionFactory {
public NamedQueryRepository getNamedQueryRepository();
Iterable<EntityNameResolver> iterateEntityNameResolvers();
/**
* Locate an EntityPersister by the entity class. The passed Class might refer to either
* the entity name directly, or it might name a proxy interface for the entity. This
* method accounts for both, preferring the direct named entity name.
*
* @param byClass The concrete Class or proxy interface for the entity to locate the persister for.
*
* @return The located EntityPersister, never {@code null}
*
* @throws HibernateException If a matching EntityPersister cannot be located
*/
EntityPersister locateEntityPersister(Class byClass);
/**
* Locate the entity persister by name.
*
* @param byName The entity name
*
* @return The located EntityPersister, never {@code null}
*
* @throws HibernateException If a matching EntityPersister cannot be located
*/
EntityPersister locateEntityPersister(String byName);
}

View File

@ -265,46 +265,7 @@ public interface SessionImplementor extends Serializable, LobCreationContext {
*
* @throws HibernateException
*/
public ScrollableResults scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters)
throws HibernateException;
/**
* Retreive the currently set value for a filter parameter.
*
* @param filterParameterName The filter parameter name in the format
* {FILTER_NAME.PARAMETER_NAME}.
*
* @return The filter parameter value.
*
* @deprecated use #getLoadQueryInfluencers instead
*/
@Deprecated
public Object getFilterParameterValue(String filterParameterName);
/**
* Retrieve the type for a given filter parameter.
*
* @param filterParameterName The filter parameter name in the format
* {FILTER_NAME.PARAMETER_NAME}.
*
* @return The filter param type
*
* @deprecated use #getLoadQueryInfluencers instead
*/
@Deprecated
public Type getFilterParameterType(String filterParameterName);
/**
* Return the currently enabled filters. The filter map is keyed by filter
* name, with values corresponding to the {@link org.hibernate.internal.FilterImpl}
* instance.
*
* @return The currently enabled filters.
*
* @deprecated use #getLoadQueryInfluencers instead
*/
@Deprecated
public Map getEnabledFilters();
public ScrollableResults scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters);
public int getDontFlushFromFind();
@ -359,26 +320,6 @@ public interface SessionImplementor extends Serializable, LobCreationContext {
public void afterScrollOperation();
/**
* Get the <i>internal</i> fetch profile currently associated with this session.
*
* @return The current internal fetch profile, or null if none currently associated.
*
* @deprecated use #getLoadQueryInfluencers instead
*/
@Deprecated
public String getFetchProfile();
/**
* Set the current <i>internal</i> fetch profile for this session.
*
* @param name The internal fetch profile name to use
*
* @deprecated use {@link #getLoadQueryInfluencers} instead
*/
@Deprecated
public void setFetchProfile(String name);
/**
* Retrieve access to the session's transaction coordinator.
*

View File

@ -297,14 +297,14 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
}
}
String previousFetchProfile = source.getFetchProfile();
source.setFetchProfile( "merge" );
String previousFetchProfile = source.getLoadQueryInfluencers().getInternalFetchProfile();
source.getLoadQueryInfluencers().setInternalFetchProfile( "merge" );
//we must clone embedded composite identifiers, or
//we will get back the same instance that we pass in
final Serializable clonedIdentifier = (Serializable) persister.getIdentifierType()
.deepCopy( id, source.getFactory() );
final Object result = source.get( entityName, clonedIdentifier );
source.setFetchProfile( previousFetchProfile );
source.getLoadQueryInfluencers().setInternalFetchProfile( previousFetchProfile );
if ( result == null ) {
//TODO: we should throw an exception if we really *know* for sure

View File

@ -313,7 +313,7 @@ public abstract class AbstractSessionImpl
}
protected HQLQueryPlan getHQLQueryPlan(String query, boolean shallow) throws HibernateException {
return factory.getQueryPlanCache().getHQLQueryPlan( query, shallow, getEnabledFilters() );
return factory.getQueryPlanCache().getHQLQueryPlan( query, shallow, getLoadQueryInfluencers().getEnabledFilters() );
}
protected NativeSQLQueryPlan getNativeSQLQueryPlan(NativeSQLQuerySpecification spec) throws HibernateException {

View File

@ -38,6 +38,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@ -124,6 +125,7 @@ import org.hibernate.id.UUIDGenerator;
import org.hibernate.id.factory.IdentifierGeneratorFactory;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.internal.util.config.ConfigurationException;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.PersistentClass;
@ -194,6 +196,7 @@ public final class SessionFactoryImpl
private final transient Map<String,EntityPersister> entityPersisters;
private final transient Map<String,ClassMetadata> classMetadata;
private final transient Map<Class,String> entityProxyInterfaceMap;
private final transient Map<String,CollectionPersister> collectionPersisters;
private final transient Map<String,CollectionMetadata> collectionMetadata;
private final transient Map<String,Set<String>> collectionRolesByEntityParticipant;
@ -339,6 +342,7 @@ public final class SessionFactoryImpl
this.entityPersisters = new HashMap<String,EntityPersister>();
Map cacheAccessStrategiesMap = new HashMap();
Map<String,ClassMetadata> inFlightClassMetadataMap = new HashMap<String,ClassMetadata>();
this.entityProxyInterfaceMap = CollectionHelper.concurrentMap( metadata.getEntityBindings().size() );
for ( final PersistentClass model : metadata.getEntityBindings() ) {
final String cacheRegionName = cacheRegionPrefix + model.getRootClass().getCacheRegionName();
// cache region is defined by the root-class in the hierarchy...
@ -364,6 +368,35 @@ public final class SessionFactoryImpl
);
entityPersisters.put( model.getEntityName(), cp );
inFlightClassMetadataMap.put( model.getEntityName(), cp.getClassMetadata() );
if ( cp.getConcreteProxyClass() != null
&& cp.getConcreteProxyClass().isInterface()
&& !Map.class.isAssignableFrom( cp.getConcreteProxyClass() )
&& cp.getMappedClass() != cp.getConcreteProxyClass() ) {
// IMPL NOTE : we exclude Map based proxy interfaces here because that should
// indicate MAP entity mode.0
if ( cp.getMappedClass().equals( cp.getConcreteProxyClass() ) ) {
// this part handles an odd case in the Hibernate test suite where we map an interface
// as the class and the proxy. I cannot think of a real life use case for that
// specific test, but..
LOG.debugf( "Entity [%s] mapped same interface [%s] as class and proxy", cp.getEntityName(), cp.getMappedClass() );
}
else {
final String old = entityProxyInterfaceMap.put( cp.getConcreteProxyClass(), cp.getEntityName() );
if ( old != null ) {
throw new HibernateException(
String.format(
Locale.ENGLISH,
"Multiple entities [%s, %s] named the same interface [%s] as their proxy which is not supported",
old,
cp.getEntityName(),
cp.getConcreteProxyClass().getName()
)
);
}
}
}
}
this.classMetadata = Collections.unmodifiableMap( inFlightClassMetadataMap );
@ -741,8 +774,14 @@ public final class SessionFactoryImpl
return namedQueryRepository.checkNamedQueries( queryPlanCache );
}
@Override
public Map<String, EntityPersister> getEntityPersisters() {
return entityPersisters;
}
@Override
public EntityPersister getEntityPersister(String entityName) throws MappingException {
EntityPersister result = entityPersisters.get(entityName);
EntityPersister result = entityPersisters.get( entityName );
if ( result == null ) {
throw new MappingException( "Unknown entity: " + entityName );
}
@ -750,13 +789,34 @@ public final class SessionFactoryImpl
}
@Override
public Map<String, CollectionPersister> getCollectionPersisters() {
return collectionPersisters;
public EntityPersister locateEntityPersister(Class byClass) {
EntityPersister entityPersister = entityPersisters.get( byClass.getName() );
if ( entityPersister == null ) {
String mappedEntityName = entityProxyInterfaceMap.get( byClass );
if ( mappedEntityName != null ) {
entityPersister = entityPersisters.get( mappedEntityName );
}
}
if ( entityPersister == null ) {
throw new HibernateException( "Unable to locate persister: " + byClass.getName() );
}
return entityPersister;
}
@Override
public Map<String, EntityPersister> getEntityPersisters() {
return entityPersisters;
public EntityPersister locateEntityPersister(String byName) {
final EntityPersister entityPersister = entityPersisters.get( byName );
if ( entityPersister == null ) {
throw new HibernateException( "Unable to locate persister: " + byName );
}
return entityPersister;
}
@Override
public Map<String, CollectionPersister> getCollectionPersisters() {
return collectionPersisters;
}
public CollectionPersister getCollectionPersister(String role) throws MappingException {
@ -865,7 +925,7 @@ public final class SessionFactoryImpl
}
public CollectionMetadata getCollectionMetadata(String roleName) throws HibernateException {
return collectionMetadata.get(roleName);
return collectionMetadata.get( roleName );
}
public ClassMetadata getClassMetadata(String entityName) throws HibernateException {

View File

@ -23,8 +23,6 @@
*/
package org.hibernate.internal;
import javax.persistence.EntityNotFoundException;
import javax.transaction.SystemException;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
@ -44,10 +42,9 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.EntityNotFoundException;
import javax.transaction.SystemException;
import org.jboss.logging.Logger;
import org.hibernate.AssertionFailure;
import org.hibernate.CacheMode;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.Criteria;
@ -142,7 +139,6 @@ import org.hibernate.event.spi.ResolveNaturalIdEventListener;
import org.hibernate.event.spi.SaveOrUpdateEvent;
import org.hibernate.event.spi.SaveOrUpdateEventListener;
import org.hibernate.internal.CriteriaImpl.CriterionEntry;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.jdbc.ReturningWork;
import org.hibernate.jdbc.Work;
import org.hibernate.jdbc.WorkExecutor;
@ -164,7 +160,8 @@ import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoo
import org.hibernate.resource.transaction.spi.TransactionStatus;
import org.hibernate.stat.SessionStatistics;
import org.hibernate.stat.internal.SessionStatisticsImpl;
import org.hibernate.type.Type;
import org.jboss.logging.Logger;
/**
* Concrete implementation of a Session.
@ -1022,7 +1019,7 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
}
@Override
public IdentifierLoadAccessImpl byId(Class entityClass) {
public <T> IdentifierLoadAccessImpl<T> byId(Class<T> entityClass) {
return new IdentifierLoadAccessImpl( entityClass );
}
@ -1250,7 +1247,7 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
}
finally {
dontFlushFromFind--;
afterOperation(success);
afterOperation( success );
delayedAfterCompletion();
}
return results;
@ -1503,12 +1500,22 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
if ( roleAfterFlush == null ) {
throw new QueryException( "The collection was unreferenced" );
}
plan = factory.getQueryPlanCache().getFilterQueryPlan( filter, roleAfterFlush.getRole(), shallow, getEnabledFilters() );
plan = factory.getQueryPlanCache().getFilterQueryPlan(
filter,
roleAfterFlush.getRole(),
shallow,
getLoadQueryInfluencers().getEnabledFilters()
);
}
else {
// otherwise, we only need to flush if there are in-memory changes
// to the queried tables
plan = factory.getQueryPlanCache().getFilterQueryPlan( filter, roleBeforeFlush.getRole(), shallow, getEnabledFilters() );
plan = factory.getQueryPlanCache().getFilterQueryPlan(
filter,
roleBeforeFlush.getRole(),
shallow,
getLoadQueryInfluencers().getEnabledFilters()
);
if ( autoFlushIfRequired( plan.getQuerySpaces() ) ) {
// might need to run a different filter entirely after the flush
// because the collection role may have changed
@ -1518,7 +1525,12 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
if ( roleAfterFlush == null ) {
throw new QueryException( "The collection was dereferenced" );
}
plan = factory.getQueryPlanCache().getFilterQueryPlan( filter, roleAfterFlush.getRole(), shallow, getEnabledFilters() );
plan = factory.getQueryPlanCache().getFilterQueryPlan(
filter,
roleAfterFlush.getRole(),
shallow,
getLoadQueryInfluencers().getEnabledFilters()
);
}
}
}
@ -2080,43 +2092,6 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
loadQueryInfluencers.disableFilter( filterName );
}
@Override
public Object getFilterParameterValue(String filterParameterName) {
errorIfClosed();
checkTransactionSynchStatus();
return loadQueryInfluencers.getFilterParameterValue( filterParameterName );
}
@Override
public Type getFilterParameterType(String filterParameterName) {
errorIfClosed();
checkTransactionSynchStatus();
return loadQueryInfluencers.getFilterParameterType( filterParameterName );
}
@Override
public Map getEnabledFilters() {
errorIfClosed();
checkTransactionSynchStatus();
return loadQueryInfluencers.getEnabledFilters();
}
// internal fetch profile support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Override
public String getFetchProfile() {
checkTransactionSynchStatus();
return loadQueryInfluencers.getInternalFetchProfile();
}
@Override
public void setFetchProfile(String fetchProfile) {
errorIfClosed();
checkTransactionSynchStatus();
loadQueryInfluencers.setInternalFetchProfile( fetchProfile );
}
// fetch profile support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -2542,7 +2517,7 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
}
}
private class IdentifierLoadAccessImpl implements IdentifierLoadAccess {
private class IdentifierLoadAccessImpl<T> implements IdentifierLoadAccess<T> {
private final EntityPersister entityPersister;
private LockOptions lockOptions;
@ -2554,22 +2529,23 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
this( locateEntityPersister( entityName ) );
}
private IdentifierLoadAccessImpl(Class entityClass) {
this( entityClass.getName() );
private IdentifierLoadAccessImpl(Class<T> entityClass) {
this( locateEntityPersister( entityClass ) );
}
@Override
public final IdentifierLoadAccessImpl with(LockOptions lockOptions) {
public final IdentifierLoadAccessImpl<T> with(LockOptions lockOptions) {
this.lockOptions = lockOptions;
return this;
}
@Override
public final Object getReference(Serializable id) {
@SuppressWarnings("unchecked")
public final T getReference(Serializable id) {
if ( this.lockOptions != null ) {
LoadEvent event = new LoadEvent( id, entityPersister.getEntityName(), lockOptions, SessionImpl.this );
fireLoad( event, LoadEventListener.LOAD );
return event.getResult();
return (T) event.getResult();
}
LoadEvent event = new LoadEvent( id, entityPersister.getEntityName(), false, SessionImpl.this );
@ -2580,7 +2556,7 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
getFactory().getEntityNotFoundDelegate().handleEntityNotFound( entityPersister.getEntityName(), id );
}
success = true;
return event.getResult();
return (T) event.getResult();
}
finally {
afterOperation( success );
@ -2588,11 +2564,12 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
}
@Override
public final Object load(Serializable id) {
@SuppressWarnings("unchecked")
public final T load(Serializable id) {
if ( this.lockOptions != null ) {
LoadEvent event = new LoadEvent( id, entityPersister.getEntityName(), lockOptions, SessionImpl.this );
fireLoad( event, LoadEventListener.GET );
return event.getResult();
return (T) event.getResult();
}
LoadEvent event = new LoadEvent( id, entityPersister.getEntityName(), false, SessionImpl.this );
@ -2607,19 +2584,19 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
finally {
afterOperation( success );
}
return event.getResult();
return (T) event.getResult();
}
}
private EntityPersister locateEntityPersister(Class entityClass) {
return factory.locateEntityPersister( entityClass );
}
private EntityPersister locateEntityPersister(String entityName) {
final EntityPersister entityPersister = factory.getEntityPersister( entityName );
if ( entityPersister == null ) {
throw new HibernateException( "Unable to locate persister: " + entityName );
}
return entityPersister;
return factory.locateEntityPersister( entityName );
}
private abstract class BaseNaturalIdLoadAccessImpl {
private abstract class BaseNaturalIdLoadAccessImpl<T> {
private final EntityPersister entityPersister;
private LockOptions lockOptions;
private boolean synchronizationEnabled = true;
@ -2634,15 +2611,7 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
}
}
private BaseNaturalIdLoadAccessImpl(String entityName) {
this( locateEntityPersister( entityName ) );
}
private BaseNaturalIdLoadAccessImpl(Class entityClass) {
this( entityClass.getName() );
}
public BaseNaturalIdLoadAccessImpl with(LockOptions lockOptions) {
public BaseNaturalIdLoadAccessImpl<T> with(LockOptions lockOptions) {
this.lockOptions = lockOptions;
return this;
}
@ -2726,7 +2695,7 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
}
}
private class NaturalIdLoadAccessImpl extends BaseNaturalIdLoadAccessImpl implements NaturalIdLoadAccess {
private class NaturalIdLoadAccessImpl<T> extends BaseNaturalIdLoadAccessImpl<T> implements NaturalIdLoadAccess<T> {
private final Map<String, Object> naturalIdParameters = new LinkedHashMap<String, Object>();
private NaturalIdLoadAccessImpl(EntityPersister entityPersister) {
@ -2738,43 +2707,45 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
}
private NaturalIdLoadAccessImpl(Class entityClass) {
this( entityClass.getName() );
this( locateEntityPersister( entityClass ) );
}
@Override
public NaturalIdLoadAccessImpl with(LockOptions lockOptions) {
return (NaturalIdLoadAccessImpl) super.with( lockOptions );
public NaturalIdLoadAccessImpl<T> with(LockOptions lockOptions) {
return (NaturalIdLoadAccessImpl<T>) super.with( lockOptions );
}
@Override
public NaturalIdLoadAccess using(String attributeName, Object value) {
public NaturalIdLoadAccess<T> using(String attributeName, Object value) {
naturalIdParameters.put( attributeName, value );
return this;
}
@Override
public NaturalIdLoadAccessImpl setSynchronizationEnabled(boolean synchronizationEnabled) {
public NaturalIdLoadAccessImpl<T> setSynchronizationEnabled(boolean synchronizationEnabled) {
super.synchronizationEnabled( synchronizationEnabled );
return this;
}
@Override
public final Object getReference() {
@SuppressWarnings("unchecked")
public final T getReference() {
final Serializable entityId = resolveNaturalId( this.naturalIdParameters );
if ( entityId == null ) {
return null;
}
return this.getIdentifierLoadAccess().getReference( entityId );
return (T) this.getIdentifierLoadAccess().getReference( entityId );
}
@Override
public final Object load() {
@SuppressWarnings("unchecked")
public final T load() {
final Serializable entityId = resolveNaturalId( this.naturalIdParameters );
if ( entityId == null ) {
return null;
}
try {
return this.getIdentifierLoadAccess().load( entityId );
return (T) this.getIdentifierLoadAccess().load( entityId );
}
catch (EntityNotFoundException enf) {
// OK
@ -2786,7 +2757,7 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
}
}
private class SimpleNaturalIdLoadAccessImpl extends BaseNaturalIdLoadAccessImpl implements SimpleNaturalIdLoadAccess {
private class SimpleNaturalIdLoadAccessImpl<T> extends BaseNaturalIdLoadAccessImpl<T> implements SimpleNaturalIdLoadAccess<T> {
private final String naturalIdAttributeName;
private SimpleNaturalIdLoadAccessImpl(EntityPersister entityPersister) {
@ -2807,12 +2778,12 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
}
private SimpleNaturalIdLoadAccessImpl(Class entityClass) {
this( entityClass.getName() );
this( locateEntityPersister( entityClass ) );
}
@Override
public final SimpleNaturalIdLoadAccessImpl with(LockOptions lockOptions) {
return (SimpleNaturalIdLoadAccessImpl) super.with( lockOptions );
public final SimpleNaturalIdLoadAccessImpl<T> with(LockOptions lockOptions) {
return (SimpleNaturalIdLoadAccessImpl<T>) super.with( lockOptions );
}
private Map<String, Object> getNaturalIdParameters(Object naturalIdValue) {
@ -2820,28 +2791,30 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
}
@Override
public SimpleNaturalIdLoadAccessImpl setSynchronizationEnabled(boolean synchronizationEnabled) {
public SimpleNaturalIdLoadAccessImpl<T> setSynchronizationEnabled(boolean synchronizationEnabled) {
super.synchronizationEnabled( synchronizationEnabled );
return this;
}
@Override
public Object getReference(Object naturalIdValue) {
@SuppressWarnings("unchecked")
public T getReference(Object naturalIdValue) {
final Serializable entityId = resolveNaturalId( getNaturalIdParameters( naturalIdValue ) );
if ( entityId == null ) {
return null;
}
return this.getIdentifierLoadAccess().getReference( entityId );
return (T) this.getIdentifierLoadAccess().getReference( entityId );
}
@Override
public Object load(Object naturalIdValue) {
@SuppressWarnings("unchecked")
public T load(Object naturalIdValue) {
final Serializable entityId = resolveNaturalId( getNaturalIdParameters( naturalIdValue ) );
if ( entityId == null ) {
return null;
}
try {
return this.getIdentifierLoadAccess().load( entityId );
return (T) this.getIdentifierLoadAccess().load( entityId );
}
catch (EntityNotFoundException enf) {
// OK

View File

@ -28,7 +28,6 @@ import java.sql.Connection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.transaction.SystemException;
import org.hibernate.CacheMode;
@ -74,7 +73,6 @@ import org.hibernate.resource.jdbc.spi.JdbcSessionContext;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.resource.transaction.TransactionCoordinator;
import org.hibernate.resource.transaction.spi.TransactionStatus;
import org.hibernate.type.Type;
/**
* @author Gavin King
@ -90,6 +88,17 @@ public class StatelessSessionImpl extends AbstractSessionImpl implements Statele
private long timestamp;
private JdbcSessionContext jdbcSessionContext;
private LoadQueryInfluencers statelessLoadQueryInfluencers = new LoadQueryInfluencers( null ) {
@Override
public String getInternalFetchProfile() {
return null;
}
@Override
public void setInternalFetchProfile(String internalFetchProfile) {
}
};
StatelessSessionImpl(
Connection connection,
String tenantIdentifier,
@ -277,15 +286,14 @@ public class StatelessSessionImpl extends AbstractSessionImpl implements Statele
final CacheKey ck = generateCacheKey( id, persister.getIdentifierType(), persister.getRootEntityName() );
persister.getCacheAccessStrategy().evict( ck );
}
String previousFetchProfile = this.getFetchProfile();
String previousFetchProfile = this.getLoadQueryInfluencers().getInternalFetchProfile();
Object result = null;
try {
this.setFetchProfile( "refresh" );
this.getLoadQueryInfluencers().setInternalFetchProfile( "refresh" );
result = persister.load( id, entity, lockMode, this );
}
finally {
this.setFetchProfile( previousFetchProfile );
this.getLoadQueryInfluencers().setInternalFetchProfile( previousFetchProfile );
}
UnresolvableObjectException.throwIfNull( result, id, persister.getEntityName() );
}
@ -443,11 +451,6 @@ public class StatelessSessionImpl extends AbstractSessionImpl implements Statele
return 0;
}
@Override
public Map getEnabledFilters() {
return Collections.EMPTY_MAP;
}
@Override
public Serializable getContextEntityIdentifier(Object object) {
errorIfClosed();
@ -476,16 +479,6 @@ public class StatelessSessionImpl extends AbstractSessionImpl implements Statele
return null;
}
@Override
public Type getFilterParameterType(String filterParameterName) {
throw new UnsupportedOperationException();
}
@Override
public Object getFilterParameterValue(String filterParameterName) {
throw new UnsupportedOperationException();
}
@Override
public FlushMode getFlushMode() {
return FlushMode.COMMIT;
@ -725,18 +718,9 @@ public class StatelessSessionImpl extends AbstractSessionImpl implements Statele
public void flush() {
}
@Override
public String getFetchProfile() {
return null;
}
@Override
public LoadQueryInfluencers getLoadQueryInfluencers() {
return LoadQueryInfluencers.NONE;
}
@Override
public void setFetchProfile(String name) {
return statelessLoadQueryInfluencers;
}
@Override

View File

@ -702,7 +702,7 @@ public abstract class AbstractCollectionPersister
if ( subselectInitializer != null ) {
return subselectInitializer;
}
else if ( session.getEnabledFilters().isEmpty() ) {
else if ( session.getLoadQueryInfluencers().getEnabledFilters().isEmpty() ) {
return initializer;
}
else {
@ -1875,8 +1875,8 @@ public abstract class AbstractCollectionPersister
@Override
public boolean isAffectedByEnabledFilters(SessionImplementor session) {
return filterHelper.isAffectedBy( session.getEnabledFilters() ) ||
( isManyToMany() && manyToManyFilterHelper.isAffectedBy( session.getEnabledFilters() ) );
return filterHelper.isAffectedBy( session.getLoadQueryInfluencers().getEnabledFilters() ) ||
( isManyToMany() && manyToManyFilterHelper.isAffectedBy( session.getLoadQueryInfluencers().getEnabledFilters() ) );
}
public boolean isSubselectLoadable() {

View File

@ -39,6 +39,7 @@ import org.jboss.logging.Logger;
import org.junit.Test;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.Query;
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
@ -663,7 +664,9 @@ public class SQLFunctionsInterSystemsTest extends BaseCoreFunctionalTestCase {
new Work() {
@Override
public void execute(Connection connection) throws SQLException {
Statement stmt = ((SessionImplementor)s).getJdbcCoordinator().getStatementPreparer().createStatement();
Statement stmt = ( (SessionImplementor) s ).getJdbcCoordinator()
.getStatementPreparer()
.createStatement();
String create_function = "CREATE FUNCTION SQLUser.TestInterSystemsFunctionsClass_spLock\n" +
" ( INOUT pHandle %SQLProcContext, \n" +
" ROWID INTEGER \n" +
@ -675,7 +678,10 @@ public class SQLFunctionsInterSystemsTest extends BaseCoreFunctionalTestCase {
" {\n" +
" q 0\n" +
" }";
((SessionImplementor)s).getJdbcCoordinator().getResultSetReturn().executeUpdate( stmt, create_function );
( (SessionImplementor) s ).getJdbcCoordinator().getResultSetReturn().executeUpdate(
stmt,
create_function
);
}
}
);
@ -684,7 +690,7 @@ public class SQLFunctionsInterSystemsTest extends BaseCoreFunctionalTestCase {
s.beginTransaction();
TestInterSystemsFunctionsClass object = new TestInterSystemsFunctionsClass( Long.valueOf( 10 ) );
object.setDateText("1977-07-03");
object.setDateText( "1977-07-03" );
object.setDate1( testvalue );
object.setDate3( testvalue3 );
s.save( object );
@ -693,9 +699,9 @@ public class SQLFunctionsInterSystemsTest extends BaseCoreFunctionalTestCase {
Session s2 = openSession();
s2.beginTransaction();
TestInterSystemsFunctionsClass test = (TestInterSystemsFunctionsClass) s2.get(TestInterSystemsFunctionsClass.class, Long.valueOf(10));
TestInterSystemsFunctionsClass test = s2.get(TestInterSystemsFunctionsClass.class, 10L );
assertTrue( test.getDate1().equals(testvalue));
test = (TestInterSystemsFunctionsClass) s2.get(TestInterSystemsFunctionsClass.class, Long.valueOf(10), LockMode.UPGRADE);
test = (TestInterSystemsFunctionsClass) s2.byId( TestInterSystemsFunctionsClass.class ).with( LockOptions.NONE ).load( 10L );
assertTrue( test.getDate1().equals(testvalue));
Date value = (Date) s2.createQuery( "select nvl(o.date,o.dateText) from TestInterSystemsFunctionsClass as o" )
.list()

View File

@ -84,7 +84,7 @@
<subclass
name="Trivial"
proxy="FooProxy"
proxy="TrivialProxy"
discriminator-value="T"/>
<subclass

View File

@ -128,7 +128,7 @@
<subclass
name="Trivial"
proxy="FooProxy"
proxy="TrivialProxy"
discriminator-value="T"/>
<subclass

View File

@ -6,6 +6,7 @@ import java.io.Serializable;
import org.junit.Test;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.Session;
import org.hibernate.dialect.HSQLDialect;
@ -43,16 +44,16 @@ public class IJTest extends LegacyTestCase {
s.beginTransaction();
j = (J) s.get(I.class, jid);
i = (I) s.get(I.class, iid);
assertTrue( i.getClass()==I.class );
assertTrue( i.getClass() == I.class );
j.setAmount( 0.5f );
s.lock(i, LockMode.UPGRADE);
s.lock( i, LockMode.UPGRADE );
s.getTransaction().commit();
s.close();
s = sessionFactory().openSession();
s.beginTransaction();
j = (J) s.get(I.class, jid, LockMode.UPGRADE);
i = (I) s.get(I.class, iid, LockMode.UPGRADE);
j = (J) s.byId( I.class ).with( LockOptions.UPGRADE ).load( jid );
i = (I) s.byId( I.class ).with( LockOptions.UPGRADE ).load( iid );
s.getTransaction().commit();
s.close();

View File

@ -42,6 +42,7 @@ import org.hibernate.FetchMode;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.ObjectNotFoundException;
import org.hibernate.ReplicationMode;
import org.hibernate.Session;
@ -1100,13 +1101,13 @@ public class ParentChildTest extends LegacyTestCase {
Simple s4 = new Simple( Long.valueOf(4) );
s4.setCount(4);
Simple s5 = new Simple( Long.valueOf(5) );
s5.setCount(5);
s5.setCount( 5 );
s.save( s1 );
s.save( s2 );
s.save( s3 );
s.save( s4 );
s.save( s5 );
assertTrue( s.getCurrentLockMode(s1)==LockMode.WRITE );
assertTrue( s.getCurrentLockMode( s1 ) == LockMode.WRITE );
tx.commit();
s.close();
@ -1118,9 +1119,9 @@ public class ParentChildTest extends LegacyTestCase {
assertTrue( s.getCurrentLockMode(s2)==LockMode.READ );
s3 = (Simple) s.load(Simple.class, new Long(3), LockMode.UPGRADE);
assertTrue( s.getCurrentLockMode(s3)==LockMode.UPGRADE );
s4 = (Simple) s.get(Simple.class, new Long(4), LockMode.UPGRADE_NOWAIT);
s4 = (Simple) s.byId( Simple.class ).with( new LockOptions( LockMode.UPGRADE_NOWAIT ) ).load( 4L );
assertTrue( s.getCurrentLockMode(s4)==LockMode.UPGRADE_NOWAIT );
s5 = (Simple) s.get(Simple.class, new Long(5), LockMode.UPGRADE_SKIPLOCKED);
s5 = (Simple) s.byId( Simple.class ).with( new LockOptions( LockMode.UPGRADE_SKIPLOCKED ) ).load( 5L );
assertTrue( s.getCurrentLockMode(s5)==LockMode.UPGRADE_SKIPLOCKED );
s1 = (Simple) s.load(Simple.class, new Long(1), LockMode.UPGRADE); //upgrade

View File

@ -0,0 +1,30 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2015, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.legacy;
/**
* @author Steve Ebersole
*/
public interface TrivialProxy extends FooProxy {
}

View File

@ -22,21 +22,22 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.lob;
import java.sql.Blob;
import junit.framework.AssertionFailedError;
import org.hibernate.dialect.TeradataDialect;
import org.hibernate.testing.SkipForDialect;
import org.junit.Assert;
import org.junit.Test;
import org.hibernate.Hibernate;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.Session;
import org.hibernate.dialect.TeradataDialect;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Assert;
import org.junit.Test;
import junit.framework.AssertionFailedError;
import static org.junit.Assert.assertNotNull;
@ -76,7 +77,7 @@ public class BlobLocatorTest extends BaseCoreFunctionalTestCase {
s = openSession();
s.beginTransaction();
entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
entity = s.get( LobHolder.class, entity.getId() );
Assert.assertEquals( BLOB_SIZE, entity.getBlobLocator().length() );
assertEquals( original, extractData( entity.getBlobLocator() ) );
s.getTransaction().commit();
@ -86,7 +87,7 @@ public class BlobLocatorTest extends BaseCoreFunctionalTestCase {
if ( getDialect().supportsLobValueChangePropogation() ) {
s = openSession();
s.beginTransaction();
entity = ( LobHolder ) s.get( LobHolder.class, entity.getId(), LockMode.UPGRADE );
entity = ( LobHolder ) s.byId( LobHolder.class ).with( LockOptions.UPGRADE ).load( entity.getId() );
entity.getBlobLocator().truncate( 1 );
entity.getBlobLocator().setBytes( 1, changed );
s.getTransaction().commit();
@ -94,7 +95,7 @@ public class BlobLocatorTest extends BaseCoreFunctionalTestCase {
s = openSession();
s.beginTransaction();
entity = ( LobHolder ) s.get( LobHolder.class, entity.getId(), LockMode.UPGRADE );
entity = ( LobHolder ) s.byId( LobHolder.class ).with( LockOptions.UPGRADE ).load( entity.getId() );
assertNotNull( entity.getBlobLocator() );
Assert.assertEquals( BLOB_SIZE, entity.getBlobLocator().length() );
assertEquals( changed, extractData( entity.getBlobLocator() ) );
@ -107,7 +108,7 @@ public class BlobLocatorTest extends BaseCoreFunctionalTestCase {
// test mutation via supplying a new clob locator instance...
s = openSession();
s.beginTransaction();
entity = ( LobHolder ) s.get( LobHolder.class, entity.getId(), LockMode.UPGRADE );
entity = ( LobHolder ) s.byId( LobHolder.class ).with( LockOptions.UPGRADE ).load( entity.getId() );
assertNotNull( entity.getBlobLocator() );
Assert.assertEquals( BLOB_SIZE, entity.getBlobLocator().length() );
assertEquals( original, extractData( entity.getBlobLocator() ) );
@ -118,7 +119,7 @@ public class BlobLocatorTest extends BaseCoreFunctionalTestCase {
// test empty blob
s = openSession();
s.beginTransaction();
entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
entity = s.get( LobHolder.class, entity.getId() );
Assert.assertEquals( BLOB_SIZE, entity.getBlobLocator().length() );
assertEquals( changed, extractData( entity.getBlobLocator() ) );
entity.setBlobLocator( s.getLobHelper().createBlob( empty ) );
@ -127,7 +128,7 @@ public class BlobLocatorTest extends BaseCoreFunctionalTestCase {
s = openSession();
s.beginTransaction();
entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
entity = s.get( LobHolder.class, entity.getId() );
if ( entity.getBlobLocator() != null) {
Assert.assertEquals( empty.length, entity.getBlobLocator().length() );
assertEquals( empty, extractData( entity.getBlobLocator() ) );
@ -162,7 +163,7 @@ public class BlobLocatorTest extends BaseCoreFunctionalTestCase {
// at that point it is unbounded...
s = openSession();
s.beginTransaction();
entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
entity = s.get( LobHolder.class, entity.getId() );
s.getTransaction().commit();
s.close();

View File

@ -25,17 +25,17 @@ package org.hibernate.test.lob;
import java.sql.Clob;
import org.hibernate.dialect.TeradataDialect;
import org.hibernate.testing.SkipForDialect;
import org.junit.Test;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.Session;
import org.hibernate.dialect.SybaseASE157Dialect;
import org.hibernate.dialect.TeradataDialect;
import org.hibernate.type.descriptor.java.DataHelper;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.type.descriptor.java.DataHelper;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@ -79,7 +79,7 @@ public class ClobLocatorTest extends BaseCoreFunctionalTestCase {
s = openSession();
s.beginTransaction();
entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
entity = s.get( LobHolder.class, entity.getId() );
assertEquals( CLOB_SIZE, entity.getClobLocator().length() );
assertEquals( original, extractData( entity.getClobLocator() ) );
s.getTransaction().commit();
@ -89,7 +89,7 @@ public class ClobLocatorTest extends BaseCoreFunctionalTestCase {
if ( getDialect().supportsLobValueChangePropogation() ) {
s = openSession();
s.beginTransaction();
entity = ( LobHolder ) s.get( LobHolder.class, entity.getId(), LockMode.UPGRADE );
entity = ( LobHolder ) s.byId( LobHolder.class ).with( LockOptions.UPGRADE ).load( entity.getId() );
entity.getClobLocator().truncate( 1 );
entity.getClobLocator().setString( 1, changed );
s.getTransaction().commit();
@ -97,7 +97,7 @@ public class ClobLocatorTest extends BaseCoreFunctionalTestCase {
s = openSession();
s.beginTransaction();
entity = ( LobHolder ) s.get( LobHolder.class, entity.getId(), LockMode.UPGRADE );
entity = ( LobHolder ) s.byId( LobHolder.class ).with( LockOptions.UPGRADE ).load( entity.getId() );
assertNotNull( entity.getClobLocator() );
assertEquals( CLOB_SIZE, entity.getClobLocator().length() );
assertEquals( changed, extractData( entity.getClobLocator() ) );
@ -110,7 +110,7 @@ public class ClobLocatorTest extends BaseCoreFunctionalTestCase {
// test mutation via supplying a new clob locator instance...
s = openSession();
s.beginTransaction();
entity = ( LobHolder ) s.get( LobHolder.class, entity.getId(), LockMode.UPGRADE );
entity = ( LobHolder ) s.byId( LobHolder.class ).with( LockOptions.UPGRADE ).load( entity.getId() );
assertNotNull( entity.getClobLocator() );
assertEquals( CLOB_SIZE, entity.getClobLocator().length() );
assertEquals( original, extractData( entity.getClobLocator() ) );
@ -122,7 +122,7 @@ public class ClobLocatorTest extends BaseCoreFunctionalTestCase {
if ( !(getDialect() instanceof SybaseASE157Dialect) ) { // Skip for Sybase. HHH-6425
s = openSession();
s.beginTransaction();
entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
entity = s.get( LobHolder.class, entity.getId() );
assertEquals( CLOB_SIZE, entity.getClobLocator().length() );
assertEquals( changed, extractData( entity.getClobLocator() ) );
entity.setClobLocator( s.getLobHelper().createClob( empty ) );
@ -131,7 +131,7 @@ public class ClobLocatorTest extends BaseCoreFunctionalTestCase {
s = openSession();
s.beginTransaction();
entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
entity = s.get( LobHolder.class, entity.getId() );
if ( entity.getClobLocator() != null) {
assertEquals( empty.length(), entity.getClobLocator().length() );
assertEquals( empty, extractData( entity.getClobLocator() ) );
@ -167,7 +167,7 @@ public class ClobLocatorTest extends BaseCoreFunctionalTestCase {
// at that point it is unbounded...
s = openSession();
s.beginTransaction();
entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
entity = s.get( LobHolder.class, entity.getId() );
s.getTransaction().commit();
s.close();

View File

@ -25,12 +25,6 @@ package org.hibernate.test.locking;
import java.util.concurrent.TimeoutException;
import org.hibernate.dialect.TeradataDialect;
import org.hibernate.testing.SkipForDialects;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.PessimisticLockException;
@ -38,11 +32,14 @@ import org.hibernate.Session;
import org.hibernate.dialect.SybaseASE15Dialect;
import org.hibernate.exception.GenericJDBCException;
import org.hibernate.exception.LockAcquisitionException;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.SkipForDialects;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.async.Executable;
import org.hibernate.testing.async.TimedExecutor;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
@ -55,7 +52,7 @@ import static org.junit.Assert.fail;
@TestForIssue( jiraKey = "HHH-5275")
@SkipForDialects( {
@SkipForDialect(value=SybaseASE15Dialect.class, strictMatching=true,
comment = "skip this test on Sybase ASE 15.5, but run it on 15.7, see HHH-6820"),
comment = "skip this test on Sybase ASE 15.5, but run it on 15.7, see HHH-6820")
})
public class LockModeTest extends BaseCoreFunctionalTestCase {
private Long id;
@ -83,7 +80,7 @@ public class LockModeTest extends BaseCoreFunctionalTestCase {
Session s1 = sessionFactory().openSession();
s1.beginTransaction();
try {
A it = (A) s1.get( A.class, id, LockMode.PESSIMISTIC_WRITE );
A it = (A) s1.byId( A.class ).with( LockOptions.UPGRADE ).load( id );
// make sure we got it
assertNotNull( it );

View File

@ -129,7 +129,7 @@ public class GetLoadTest extends BaseCoreFunctionalTestCase {
s = openSession();
s.beginTransaction();
s.delete( emp );
emp = ( Employer ) s.get( Employee.class, emp.getId() );
emp = s.get( Employer.class, emp.getId() );
s.getTransaction().commit();
s.close();

View File

@ -0,0 +1,158 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2015, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.ops.genericApi;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.Session;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.boot.MetadataSources;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test;
/**
* @author Steve Ebersole
*/
public class BasicGetLoadAccessTest extends BaseNonConfigCoreFunctionalTestCase {
@Override
protected void applyMetadataSources(MetadataSources metadataSources) {
super.applyMetadataSources( metadataSources );
metadataSources.addAnnotatedClass( User.class );
}
@Entity( name = "User" )
@Table( name = "user" )
public static class User {
private Integer id;
private String name;
public User() {
}
public User(String name) {
this.name = name;
}
@Id
@GeneratedValue( generator = "increment" )
@GenericGenerator( name = "increment", strategy = "increment" )
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Test
public void testIt() {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// create a row
Session s = openSession();
s.beginTransaction();
s.save( new User( "steve" ) );
s.getTransaction().commit();
s.close();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// test `get` access
s = openSession();
s.beginTransaction();
User user = s.get( User.class, 1 );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
user = s.get( User.class, 1, LockMode.PESSIMISTIC_WRITE );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
user = s.get( User.class, 1, LockOptions.UPGRADE );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
user = s.byId( User.class ).load( 1 );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
user = s.byId( User.class ).with( LockOptions.UPGRADE ).load( 1 );
s.getTransaction().commit();
s.close();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// test `load` access
s = openSession();
s.beginTransaction();
user = s.load( User.class, 1 );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
user = s.load( User.class, 1, LockMode.PESSIMISTIC_WRITE );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
user = s.load( User.class, 1, LockOptions.UPGRADE );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
user = s.byId( User.class ).getReference( 1 );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
user = s.byId( User.class ).with( LockOptions.UPGRADE ).getReference( 1 );
s.getTransaction().commit();
s.close();
}
}

View File

@ -0,0 +1,180 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2015, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.ops.genericApi;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.Session;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.boot.MetadataSources;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test;
/**
* @author Steve Ebersole
*/
public class ProxiedGetLoadAccessTest extends BaseNonConfigCoreFunctionalTestCase {
@Override
protected void applyMetadataSources(MetadataSources metadataSources) {
super.applyMetadataSources( metadataSources );
metadataSources.addAnnotatedClass( UserImpl.class );
}
public static interface User {
public Integer getId();
public String getName();
public void setName(String name);
}
@Entity( name = "User" )
@Table( name = "user" )
@Proxy( proxyClass = User.class )
public static class UserImpl implements User {
private Integer id;
private String name;
public UserImpl() {
}
public UserImpl(String name) {
this.name = name;
}
@Id
@GeneratedValue( generator = "increment" )
@GenericGenerator( name = "increment", strategy = "increment" )
@Override
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Override
public String getName() {
return name;
}
@Override
public void setName(String name) {
this.name = name;
}
}
@Test
public void testIt() {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// create a row
Session s = openSession();
s.beginTransaction();
s.save( new UserImpl( "steve" ) );
s.getTransaction().commit();
s.close();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// test `get` access
s = openSession();
s.beginTransaction();
// THis technically works
User user = s.get( UserImpl.class, 1 );
user = s.get( User.class, 1 );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
user = s.get( UserImpl.class, 1, LockMode.PESSIMISTIC_WRITE );
user = s.get( User.class, 1, LockMode.PESSIMISTIC_WRITE );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
user = s.get( UserImpl.class, 1, LockOptions.UPGRADE );
user = s.get( User.class, 1, LockOptions.UPGRADE );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
user = s.byId( UserImpl.class ).load( 1 );
user = s.byId( User.class ).load( 1 );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
user = s.byId( UserImpl.class ).with( LockOptions.UPGRADE ).load( 1 );
user = s.byId( User.class ).with( LockOptions.UPGRADE ).load( 1 );
s.getTransaction().commit();
s.close();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// test `load` access
s = openSession();
s.beginTransaction();
user = s.load( UserImpl.class, 1 );
user = s.load( User.class, 1 );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
user = s.load( UserImpl.class, 1, LockMode.PESSIMISTIC_WRITE );
user = s.load( User.class, 1, LockMode.PESSIMISTIC_WRITE );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
user = s.load( UserImpl.class, 1, LockOptions.UPGRADE );
user = s.load( User.class, 1, LockOptions.UPGRADE );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
user = s.byId( UserImpl.class ).getReference( 1 );
user = s.byId( User.class ).getReference( 1 );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
user = s.byId( UserImpl.class ).with( LockOptions.UPGRADE ).getReference( 1 );
user = s.byId( User.class ).with( LockOptions.UPGRADE ).getReference( 1 );
s.getTransaction().commit();
s.close();
}
}

View File

@ -255,7 +255,7 @@ public class ProxyTest extends BaseCoreFunctionalTestCase {
dp = (DataPoint) s.load( DataPoint.class, new Long (dp.getId() ));
assertFalse( Hibernate.isInitialized(dp) );
dp2 = (DataPoint) s.get( DataPoint.class, new Long ( dp.getId() ) , LockMode.READ );
dp2 = (DataPoint) s.byId( DataPoint.class ).with( LockOptions.READ ).load( dp.getId() );
assertSame(dp, dp2);
assertTrue( Hibernate.isInitialized(dp) );
s.clear();

View File

@ -14,6 +14,7 @@ import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.internal.util.ConfigHelper;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.testing.TestForIssue;
import org.junit.Assert;
@ -120,7 +121,7 @@ public class ClassLoaderServiceImplTest {
};
}
else {
return java.util.Collections.emptyEnumeration();
return java.util.Collections.enumeration( java.util.Collections.<URL>emptyList() );
}
}

View File

@ -565,8 +565,13 @@ public class QueryImpl<X> extends AbstractQueryImpl<X> implements TypedQuery<X>,
private List<X> list() {
if (getEntityGraphQueryHint() != null) {
SessionImplementor sessionImpl = (SessionImplementor) getEntityManager().getSession();
HQLQueryPlan entityGraphQueryPlan = new HQLQueryPlan( getHibernateQuery().getQueryString(), false,
sessionImpl.getEnabledFilters(), sessionImpl.getFactory(), getEntityGraphQueryHint() );
HQLQueryPlan entityGraphQueryPlan = new HQLQueryPlan(
getHibernateQuery().getQueryString(),
false,
sessionImpl.getLoadQueryInfluencers().getEnabledFilters(),
sessionImpl.getFactory(),
getEntityGraphQueryHint()
);
// Safe to assume QueryImpl at this point.
unwrap( org.hibernate.internal.QueryImpl.class ).setQueryPlan( entityGraphQueryPlan );
}