HHH-4704 - Pass session into EntityTuplizer#setIdentifier
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18697 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
b84e1fc5fc
commit
80f250fca5
|
@ -74,7 +74,7 @@ public final class EntityIdentityInsertAction extends EntityAction {
|
||||||
}
|
}
|
||||||
//need to do that here rather than in the save event listener to let
|
//need to do that here rather than in the save event listener to let
|
||||||
//the post insert events to have a id-filled entity when IDENTITY is used (EJB3)
|
//the post insert events to have a id-filled entity when IDENTITY is used (EJB3)
|
||||||
persister.setIdentifier( instance, generatedId, session.getEntityMode() );
|
persister.setIdentifier( instance, generatedId, session );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -191,7 +191,7 @@ public abstract class AbstractSaveEventListener extends AbstractReassociateEvent
|
||||||
throw new NonUniqueObjectException( id, persister.getEntityName() );
|
throw new NonUniqueObjectException( id, persister.getEntityName() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
persister.setIdentifier( entity, id, source.getEntityMode() );
|
persister.setIdentifier( entity, id, source );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
key = null;
|
key = null;
|
||||||
|
|
|
@ -163,7 +163,7 @@ public class DefaultDeleteEventListener implements DeleteEventListener {
|
||||||
deleteEntity( source, entity, entityEntry, event.isCascadeDeleteEnabled(), persister, transientEntities );
|
deleteEntity( source, entity, entityEntry, event.isCascadeDeleteEnabled(), persister, transientEntities );
|
||||||
|
|
||||||
if ( source.getFactory().getSettings().isIdentifierRollbackEnabled() ) {
|
if ( source.getFactory().getSettings().isIdentifierRollbackEnabled() ) {
|
||||||
persister.resetIdentifier( entity, id, version, source.getEntityMode() );
|
persister.resetIdentifier( entity, id, version, source );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -221,7 +221,7 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
||||||
MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
|
MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
persister.setIdentifier( event.getInstanceToLoad(), event.getEntityId(), event.getSession().getEntityMode() );
|
persister.setIdentifier( event.getInstanceToLoad(), event.getEntityId(), event.getSession() );
|
||||||
}
|
}
|
||||||
|
|
||||||
Object entity = doLoad(event, persister, keyToLoad, options);
|
Object entity = doLoad(event, persister, keyToLoad, options);
|
||||||
|
|
|
@ -292,10 +292,10 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener
|
||||||
persister.getIdentifier( entity, source.getEntityMode() ) :
|
persister.getIdentifier( entity, source.getEntityMode() ) :
|
||||||
null;
|
null;
|
||||||
if ( copyCache.containsKey( entity ) ) {
|
if ( copyCache.containsKey( entity ) ) {
|
||||||
persister.setIdentifier( copyCache.get( entity ), id, source.getEntityMode() );
|
persister.setIdentifier( copyCache.get( entity ), id, source );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
( ( EventCache ) copyCache ).put( entity, persister.instantiate( id, source.getEntityMode() ), true ); //before cascade!
|
( ( EventCache ) copyCache ).put( entity, persister.instantiate( id, source ), true ); //before cascade!
|
||||||
//TODO: should this be Session.instantiate(Persister, ...)?
|
//TODO: should this be Session.instantiate(Persister, ...)?
|
||||||
}
|
}
|
||||||
final Object copy = copyCache.get( entity );
|
final Object copy = copyCache.get( entity );
|
||||||
|
|
|
@ -239,7 +239,7 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener
|
||||||
|
|
||||||
event.setRequestedId(
|
event.setRequestedId(
|
||||||
getUpdateId(
|
getUpdateId(
|
||||||
entity, persister, event.getRequestedId(), event.getSession().getEntityMode()
|
entity, persister, event.getRequestedId(), event.getSession()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -253,7 +253,7 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener
|
||||||
* @param entity The entity.
|
* @param entity The entity.
|
||||||
* @param persister The entity persister
|
* @param persister The entity persister
|
||||||
* @param requestedId The requested identifier
|
* @param requestedId The requested identifier
|
||||||
* @param entityMode The entity mode.
|
* @param session The session
|
||||||
*
|
*
|
||||||
* @return The id.
|
* @return The id.
|
||||||
*
|
*
|
||||||
|
@ -263,9 +263,9 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener
|
||||||
Object entity,
|
Object entity,
|
||||||
EntityPersister persister,
|
EntityPersister persister,
|
||||||
Serializable requestedId,
|
Serializable requestedId,
|
||||||
EntityMode entityMode) {
|
SessionImplementor session) {
|
||||||
// use the id assigned to the instance
|
// use the id assigned to the instance
|
||||||
Serializable id = persister.getIdentifier( entity, entityMode );
|
Serializable id = persister.getIdentifier( entity, session.getEntityMode() );
|
||||||
if ( id == null ) {
|
if ( id == null ) {
|
||||||
// assume this is a newly instantiated transient object
|
// assume this is a newly instantiated transient object
|
||||||
// which should be saved rather than updated
|
// which should be saved rather than updated
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.hibernate.HibernateException;
|
||||||
import org.hibernate.ObjectDeletedException;
|
import org.hibernate.ObjectDeletedException;
|
||||||
import org.hibernate.EntityMode;
|
import org.hibernate.EntityMode;
|
||||||
import org.hibernate.engine.EntityEntry;
|
import org.hibernate.engine.EntityEntry;
|
||||||
|
import org.hibernate.engine.SessionImplementor;
|
||||||
import org.hibernate.engine.Status;
|
import org.hibernate.engine.Status;
|
||||||
import org.hibernate.event.SaveOrUpdateEvent;
|
import org.hibernate.event.SaveOrUpdateEvent;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
@ -62,14 +63,16 @@ public class DefaultUpdateEventListener extends DefaultSaveOrUpdateEventListener
|
||||||
* If the user specified an id, assign it to the instance and use that,
|
* If the user specified an id, assign it to the instance and use that,
|
||||||
* otherwise use the id already assigned to the instance
|
* otherwise use the id already assigned to the instance
|
||||||
*/
|
*/
|
||||||
protected Serializable getUpdateId(Object entity, EntityPersister persister, Serializable requestedId, EntityMode entityMode)
|
protected Serializable getUpdateId(
|
||||||
throws HibernateException {
|
Object entity,
|
||||||
|
EntityPersister persister,
|
||||||
if ( requestedId==null ) {
|
Serializable requestedId,
|
||||||
return super.getUpdateId(entity, persister, requestedId, entityMode);
|
SessionImplementor session) throws HibernateException {
|
||||||
|
if ( requestedId == null ) {
|
||||||
|
return super.getUpdateId( entity, persister, requestedId, session );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
persister.setIdentifier(entity, requestedId, entityMode);
|
persister.setIdentifier( entity, requestedId, session );
|
||||||
return requestedId;
|
return requestedId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1409,7 +1409,7 @@ public final class SessionImpl extends AbstractSessionImpl
|
||||||
checkTransactionSynchStatus();
|
checkTransactionSynchStatus();
|
||||||
Object result = interceptor.instantiate( persister.getEntityName(), entityMode, id );
|
Object result = interceptor.instantiate( persister.getEntityName(), entityMode, id );
|
||||||
if ( result == null ) {
|
if ( result == null ) {
|
||||||
result = persister.instantiate( id, entityMode );
|
result = persister.instantiate( id, this );
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ public class StatelessSessionImpl extends AbstractSessionImpl
|
||||||
else {
|
else {
|
||||||
persister.insert(id, state, entity, this);
|
persister.insert(id, state, entity, this);
|
||||||
}
|
}
|
||||||
persister.setIdentifier(entity, id, EntityMode.POJO);
|
persister.setIdentifier( entity, id, this );
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,7 +253,7 @@ public class StatelessSessionImpl extends AbstractSessionImpl
|
||||||
Serializable id) throws HibernateException {
|
Serializable id) throws HibernateException {
|
||||||
errorIfClosed();
|
errorIfClosed();
|
||||||
return getFactory().getEntityPersister( entityName )
|
return getFactory().getEntityPersister( entityName )
|
||||||
.instantiate( id, EntityMode.POJO );
|
.instantiate( id, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object internalLoad(
|
public Object internalLoad(
|
||||||
|
|
|
@ -152,9 +152,22 @@ public interface ClassMetadata {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a class instance initialized with the given identifier
|
* Create a class instance initialized with the given identifier
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link #instantiate(Serializable, SessionImplementor)} instead
|
||||||
|
* @noinspection JavaDoc
|
||||||
*/
|
*/
|
||||||
public Object instantiate(Serializable id, EntityMode entityMode) throws HibernateException;
|
public Object instantiate(Serializable id, EntityMode entityMode) throws HibernateException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a class instance initialized with the given identifier
|
||||||
|
*
|
||||||
|
* @param id The identifier value to use (may be null to represent no value)
|
||||||
|
* @param session The session from which the request originated.
|
||||||
|
*
|
||||||
|
* @return The instantiated entity.
|
||||||
|
*/
|
||||||
|
public Object instantiate(Serializable id, SessionImplementor session);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value of a particular (named) property
|
* Get the value of a particular (named) property
|
||||||
*/
|
*/
|
||||||
|
@ -186,9 +199,28 @@ public interface ClassMetadata {
|
||||||
public Serializable getIdentifier(Object entity, EntityMode entityMode) throws HibernateException;
|
public Serializable getIdentifier(Object entity, EntityMode entityMode) throws HibernateException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the identifier of an instance (or do nothing if no identifier property)
|
* Inject the identifier value into the given entity.
|
||||||
|
* </p>
|
||||||
|
* Has no effect if the entity does not define an identifier property
|
||||||
|
*
|
||||||
|
* @param entity The entity to inject with the identifier value.
|
||||||
|
* @param id The value to be injected as the identifier.
|
||||||
|
* @param entityMode The entity mode
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link #setIdentifier(Object, Serializable, SessionImplementor)} instead.
|
||||||
|
* @noinspection JavaDoc
|
||||||
*/
|
*/
|
||||||
public void setIdentifier(Object object, Serializable id, EntityMode entityMode) throws HibernateException;
|
public void setIdentifier(Object entity, Serializable id, EntityMode entityMode) throws HibernateException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inject the identifier value into the given entity.
|
||||||
|
*
|
||||||
|
* @param entity The entity to inject with the identifier value.
|
||||||
|
* @param id The value to be injected as the identifier.
|
||||||
|
* @param session The session from which is requests originates
|
||||||
|
*/
|
||||||
|
public void setIdentifier(Object entity, Serializable id, SessionImplementor session);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does the class implement the <tt>Lifecycle</tt> interface?
|
* Does the class implement the <tt>Lifecycle</tt> interface?
|
||||||
|
|
|
@ -3801,9 +3801,19 @@ public abstract class AbstractEntityPersister
|
||||||
return getTuplizer( entityMode ).getIdentifier( object );
|
return getTuplizer( entityMode ).getIdentifier( object );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIdentifier(Object object, Serializable id, EntityMode entityMode)
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public void setIdentifier(Object entity, Serializable id, EntityMode entityMode)
|
||||||
throws HibernateException {
|
throws HibernateException {
|
||||||
getTuplizer( entityMode ).setIdentifier( object, id );
|
getTuplizer( entityMode ).setIdentifier( entity, id, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public void setIdentifier(Object entity, Serializable id, SessionImplementor session) {
|
||||||
|
getTuplizer( session ).setIdentifier( entity, id, session );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getVersion(Object object, EntityMode entityMode)
|
public Object getVersion(Object object, EntityMode entityMode)
|
||||||
|
@ -3811,9 +3821,20 @@ public abstract class AbstractEntityPersister
|
||||||
return getTuplizer( entityMode ).getVersion( object );
|
return getTuplizer( entityMode ).getVersion( object );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
public Object instantiate(Serializable id, EntityMode entityMode)
|
public Object instantiate(Serializable id, EntityMode entityMode)
|
||||||
throws HibernateException {
|
throws HibernateException {
|
||||||
return getTuplizer( entityMode ).instantiate( id );
|
return getTuplizer( entityMode ).instantiate( id, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public Object instantiate(Serializable id, SessionImplementor session)
|
||||||
|
throws HibernateException {
|
||||||
|
return getTuplizer( session ).instantiate( id, session );
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInstance(Object object, EntityMode entityMode) {
|
public boolean isInstance(Object object, EntityMode entityMode) {
|
||||||
|
@ -3825,9 +3846,16 @@ public abstract class AbstractEntityPersister
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetIdentifier(Object entity, Serializable currentId, Object currentVersion, EntityMode entityMode) {
|
public void resetIdentifier(Object entity, Serializable currentId, Object currentVersion, EntityMode entityMode) {
|
||||||
getTuplizer( entityMode ).resetIdentifier( entity, currentId, currentVersion );
|
getTuplizer( entityMode ).resetIdentifier( entity, currentId, currentVersion, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resetIdentifier(Object entity, Serializable currentId, Object currentVersion, SessionImplementor session) {
|
||||||
|
getTuplizer( session ).resetIdentifier( entity, currentId, currentVersion, session );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
public EntityPersister getSubclassEntityPersister(
|
public EntityPersister getSubclassEntityPersister(
|
||||||
Object instance,
|
Object instance,
|
||||||
SessionFactoryImplementor factory,
|
SessionFactoryImplementor factory,
|
||||||
|
|
|
@ -655,10 +655,28 @@ public interface EntityPersister extends OptimisticCacheSource {
|
||||||
*/
|
*/
|
||||||
public Serializable getIdentifier(Object object, EntityMode entityMode) throws HibernateException;
|
public Serializable getIdentifier(Object object, EntityMode entityMode) throws HibernateException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the identifier of an instance (or do nothing if no identifier property)
|
* Inject the identifier value into the given entity.
|
||||||
*/
|
* </p>
|
||||||
public void setIdentifier(Object object, Serializable id, EntityMode entityMode) throws HibernateException;
|
* Has no effect if the entity does not define an identifier property
|
||||||
|
*
|
||||||
|
* @param entity The entity to inject with the identifier value.
|
||||||
|
* @param id The value to be injected as the identifier.
|
||||||
|
* @param entityMode The entity mode
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link #setIdentifier(Object, Serializable, SessionImplementor)} instead.
|
||||||
|
* @noinspection JavaDoc
|
||||||
|
*/
|
||||||
|
public void setIdentifier(Object entity, Serializable id, EntityMode entityMode) throws HibernateException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inject the identifier value into the given entity.
|
||||||
|
*
|
||||||
|
* @param entity The entity to inject with the identifier value.
|
||||||
|
* @param id The value to be injected as the identifier.
|
||||||
|
* @param session The session from which is requests originates
|
||||||
|
*/
|
||||||
|
public void setIdentifier(Object entity, Serializable id, SessionImplementor session);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the version number (or timestamp) from the object's version property (or return null if not versioned)
|
* Get the version number (or timestamp) from the object's version property (or return null if not versioned)
|
||||||
|
@ -667,9 +685,22 @@ public interface EntityPersister extends OptimisticCacheSource {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a class instance initialized with the given identifier
|
* Create a class instance initialized with the given identifier
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link #instantiate(Serializable, SessionImplementor)} instead
|
||||||
|
* @noinspection JavaDoc
|
||||||
*/
|
*/
|
||||||
public Object instantiate(Serializable id, EntityMode entityMode) throws HibernateException;
|
public Object instantiate(Serializable id, EntityMode entityMode) throws HibernateException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a class instance initialized with the given identifier
|
||||||
|
*
|
||||||
|
* @param id The identifier value to use (may be null to represent no value)
|
||||||
|
* @param session The session from which the request originated.
|
||||||
|
*
|
||||||
|
* @return The instantiated entity.
|
||||||
|
*/
|
||||||
|
public Object instantiate(Serializable id, SessionImplementor session);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the given object an instance of this entity?
|
* Is the given object an instance of this entity?
|
||||||
*/
|
*/
|
||||||
|
@ -687,9 +718,21 @@ public interface EntityPersister extends OptimisticCacheSource {
|
||||||
* @param currentId The currently assigned identifier value.
|
* @param currentId The currently assigned identifier value.
|
||||||
* @param currentVersion The currently assigned version value.
|
* @param currentVersion The currently assigned version value.
|
||||||
* @param entityMode The entity mode represented by the entity instance.
|
* @param entityMode The entity mode represented by the entity instance.
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link #resetIdentifier(Object, Serializable, Object, SessionImplementor)} instead
|
||||||
*/
|
*/
|
||||||
public void resetIdentifier(Object entity, Serializable currentId, Object currentVersion, EntityMode entityMode);
|
public void resetIdentifier(Object entity, Serializable currentId, Object currentVersion, EntityMode entityMode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the identifier and version of the given instance back to its "unsaved" value.
|
||||||
|
*
|
||||||
|
* @param entity The entity instance
|
||||||
|
* @param currentId The currently assigned identifier value.
|
||||||
|
* @param currentVersion The currently assigned version value.
|
||||||
|
* @param session The session from which the request originated.
|
||||||
|
*/
|
||||||
|
public void resetIdentifier(Object entity, Serializable currentId, Object currentVersion, SessionImplementor session);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A request has already identified the entity-name of this persister as the mapping for the given instance.
|
* A request has already identified the entity-name of this persister as the mapping for the given instance.
|
||||||
* However, we still need to account for possible subclassing and potentially re-route to the more appropriate
|
* However, we still need to account for possible subclassing and potentially re-route to the more appropriate
|
||||||
|
|
|
@ -236,8 +236,19 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
public void setIdentifier(Object entity, Serializable id) throws HibernateException {
|
public void setIdentifier(Object entity, Serializable id) throws HibernateException {
|
||||||
|
// 99% of the time the session is not needed. Its only needed for certain brain-dead
|
||||||
|
// interpretations of JPA 2 "derived identity" support
|
||||||
|
setIdentifier( entity, id, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public void setIdentifier(Object entity, Serializable id, SessionImplementor session) {
|
||||||
if ( entityMetamodel.getIdentifierProperty().isEmbedded() ) {
|
if ( entityMetamodel.getIdentifierProperty().isEmbedded() ) {
|
||||||
if ( entity != id ) {
|
if ( entity != id ) {
|
||||||
AbstractComponentType copier = (AbstractComponentType) entityMetamodel.getIdentifierProperty().getType();
|
AbstractComponentType copier = (AbstractComponentType) entityMetamodel.getIdentifierProperty().getType();
|
||||||
|
@ -265,16 +276,31 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
public void resetIdentifier(Object entity, Serializable currentId, Object currentVersion) {
|
public void resetIdentifier(Object entity, Serializable currentId, Object currentVersion) {
|
||||||
|
// 99% of the time the session is not needed. Its only needed for certain brain-dead
|
||||||
|
// interpretations of JPA 2 "derived identity" support
|
||||||
|
resetIdentifier( entity, currentId, currentVersion, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public void resetIdentifier(
|
||||||
|
Object entity,
|
||||||
|
Serializable currentId,
|
||||||
|
Object currentVersion,
|
||||||
|
SessionImplementor session) {
|
||||||
if ( entityMetamodel.getIdentifierProperty().getIdentifierGenerator() instanceof Assigned ) {
|
if ( entityMetamodel.getIdentifierProperty().getIdentifierGenerator() instanceof Assigned ) {
|
||||||
//return currentId;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//reset the id
|
//reset the id
|
||||||
Serializable result = entityMetamodel.getIdentifierProperty()
|
Serializable result = entityMetamodel.getIdentifierProperty()
|
||||||
.getUnsavedValue()
|
.getUnsavedValue()
|
||||||
.getDefaultValue( currentId );
|
.getDefaultValue( currentId );
|
||||||
setIdentifier( entity, result );
|
setIdentifier( entity, result, session );
|
||||||
//reset the version
|
//reset the version
|
||||||
VersionProperty versionProperty = entityMetamodel.getVersionProperty();
|
VersionProperty versionProperty = entityMetamodel.getVersionProperty();
|
||||||
if ( entityMetamodel.isVersioned() ) {
|
if ( entityMetamodel.isVersioned() ) {
|
||||||
|
@ -282,10 +308,8 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
|
||||||
entity,
|
entity,
|
||||||
entityMetamodel.getVersionPropertyIndex(),
|
entityMetamodel.getVersionPropertyIndex(),
|
||||||
versionProperty.getUnsavedValue().getDefaultValue( currentVersion )
|
versionProperty.getUnsavedValue().getDefaultValue( currentVersion )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
//return the id, so we can use it to reset the proxy id
|
|
||||||
//return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,15 +445,21 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Object instantiate(Serializable id) throws HibernateException {
|
public final Object instantiate(Serializable id) throws HibernateException {
|
||||||
|
// 99% of the time the session is not needed. Its only needed for certain brain-dead
|
||||||
|
// interpretations of JPA 2 "derived identity" support
|
||||||
|
return instantiate( id, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
public final Object instantiate(Serializable id, SessionImplementor session) {
|
||||||
Object result = getInstantiator().instantiate( id );
|
Object result = getInstantiator().instantiate( id );
|
||||||
if ( id != null ) {
|
if ( id != null ) {
|
||||||
setIdentifier( result, id );
|
setIdentifier( result, id, session );
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Object instantiate() throws HibernateException {
|
public final Object instantiate() throws HibernateException {
|
||||||
return instantiate( null );
|
return instantiate( null, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void afterInitialize(Object entity, boolean lazyPropertiesAreUnfetched, SessionImplementor session) {}
|
public void afterInitialize(Object entity, boolean lazyPropertiesAreUnfetched, SessionImplementor session) {}
|
||||||
|
|
|
@ -59,9 +59,22 @@ public interface EntityTuplizer extends Tuplizer {
|
||||||
* @param id The identifier value for the entity to be instantiated.
|
* @param id The identifier value for the entity to be instantiated.
|
||||||
* @return The instantiated entity.
|
* @return The instantiated entity.
|
||||||
* @throws HibernateException
|
* @throws HibernateException
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link #instantiate(Serializable, SessionImplementor)} instead.
|
||||||
|
* @noinspection JavaDoc
|
||||||
*/
|
*/
|
||||||
public Object instantiate(Serializable id) throws HibernateException;
|
public Object instantiate(Serializable id) throws HibernateException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an entity instance initialized with the given identifier.
|
||||||
|
*
|
||||||
|
* @param id The identifier value for the entity to be instantiated.
|
||||||
|
* @param session The session from which is requests originates
|
||||||
|
*
|
||||||
|
* @return The instantiated entity.
|
||||||
|
*/
|
||||||
|
public Object instantiate(Serializable id, SessionImplementor session);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract the identifier value from the given entity.
|
* Extract the identifier value from the given entity.
|
||||||
*
|
*
|
||||||
|
@ -79,19 +92,46 @@ public interface EntityTuplizer extends Tuplizer {
|
||||||
*
|
*
|
||||||
* @param entity The entity to inject with the identifier value.
|
* @param entity The entity to inject with the identifier value.
|
||||||
* @param id The value to be injected as the identifier.
|
* @param id The value to be injected as the identifier.
|
||||||
* @throws HibernateException
|
*
|
||||||
|
* @deprecated Use {@link #setIdentifier(Object, Serializable, SessionImplementor)} instead.
|
||||||
|
* @noinspection JavaDoc
|
||||||
*/
|
*/
|
||||||
public void setIdentifier(Object entity, Serializable id) throws HibernateException;
|
public void setIdentifier(Object entity, Serializable id) throws HibernateException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inject the identifier value into the given entity.
|
||||||
|
* </p>
|
||||||
|
* Has no effect if the entity does not define an identifier property
|
||||||
|
*
|
||||||
|
* @param entity The entity to inject with the identifier value.
|
||||||
|
* @param id The value to be injected as the identifier.
|
||||||
|
* @param session The session from which is requests originates
|
||||||
|
*/
|
||||||
|
public void setIdentifier(Object entity, Serializable id, SessionImplementor session);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inject the given identifier and version into the entity, in order to
|
* Inject the given identifier and version into the entity, in order to
|
||||||
* "roll back" to their original values.
|
* "roll back" to their original values.
|
||||||
*
|
*
|
||||||
|
* @param entity The entity for which to reset the id/version values
|
||||||
* @param currentId The identifier value to inject into the entity.
|
* @param currentId The identifier value to inject into the entity.
|
||||||
* @param currentVersion The version value to inject into the entity.
|
* @param currentVersion The version value to inject into the entity.
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link #resetIdentifier(Object, Serializable, Object, SessionImplementor)} instead
|
||||||
*/
|
*/
|
||||||
public void resetIdentifier(Object entity, Serializable currentId, Object currentVersion);
|
public void resetIdentifier(Object entity, Serializable currentId, Object currentVersion);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inject the given identifier and version into the entity, in order to
|
||||||
|
* "roll back" to their original values.
|
||||||
|
*
|
||||||
|
* @param entity The entity for which to reset the id/version values
|
||||||
|
* @param currentId The identifier value to inject into the entity.
|
||||||
|
* @param currentVersion The version value to inject into the entity.
|
||||||
|
* @param session The session from which the request originated
|
||||||
|
*/
|
||||||
|
public void resetIdentifier(Object entity, Serializable currentId, Object currentVersion, SessionImplementor session);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract the value of the version property from the given entity.
|
* Extract the value of the version property from the given entity.
|
||||||
*
|
*
|
||||||
|
|
|
@ -276,7 +276,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
|
||||||
if ( session.getContextEntityIdentifier( original ) == null &&
|
if ( session.getContextEntityIdentifier( original ) == null &&
|
||||||
ForeignKeys.isTransient( associatedEntityName, original, Boolean.FALSE, session ) ) {
|
ForeignKeys.isTransient( associatedEntityName, original, Boolean.FALSE, session ) ) {
|
||||||
final Object copy = session.getFactory().getEntityPersister( associatedEntityName )
|
final Object copy = session.getFactory().getEntityPersister( associatedEntityName )
|
||||||
.instantiate( null, session.getEntityMode() );
|
.instantiate( null, session );
|
||||||
//TODO: should this be Session.instantiate(Persister, ...)?
|
//TODO: should this be Session.instantiate(Persister, ...)?
|
||||||
copyCache.put( original, copy );
|
copyCache.put( original, copy );
|
||||||
return copy;
|
return copy;
|
||||||
|
|
|
@ -62,6 +62,10 @@ public class CustomPersister implements EntityPersister {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkEntityMode(SessionImplementor session) {
|
||||||
|
checkEntityMode( session.getEntityMode() );
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isInherited() {
|
public boolean isInherited() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -183,6 +187,11 @@ public class CustomPersister implements EntityPersister {
|
||||||
( (Custom) object ).id = (String) id;
|
( (Custom) object ).id = (String) id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setIdentifier(Object entity, Serializable id, SessionImplementor session) {
|
||||||
|
checkEntityMode( session );
|
||||||
|
( (Custom) entity ).id = (String) id;
|
||||||
|
}
|
||||||
|
|
||||||
public Object getVersion(Object object, EntityMode entityMode) throws HibernateException {
|
public Object getVersion(Object object, EntityMode entityMode) throws HibernateException {
|
||||||
checkEntityMode( entityMode );
|
checkEntityMode( entityMode );
|
||||||
return null;
|
return null;
|
||||||
|
@ -190,11 +199,20 @@ public class CustomPersister implements EntityPersister {
|
||||||
|
|
||||||
public Object instantiate(Serializable id, EntityMode entityMode) throws HibernateException {
|
public Object instantiate(Serializable id, EntityMode entityMode) throws HibernateException {
|
||||||
checkEntityMode( entityMode );
|
checkEntityMode( entityMode );
|
||||||
|
return instantiate( id );
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object instantiate(Serializable id) {
|
||||||
Custom c = new Custom();
|
Custom c = new Custom();
|
||||||
c.id = (String) id;
|
c.id = (String) id;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object instantiate(Serializable id, SessionImplementor session) {
|
||||||
|
checkEntityMode( session );
|
||||||
|
return instantiate( id );
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isInstance(Object object, EntityMode entityMode) {
|
public boolean isInstance(Object object, EntityMode entityMode) {
|
||||||
checkEntityMode( entityMode );
|
checkEntityMode( entityMode );
|
||||||
return object instanceof Custom;
|
return object instanceof Custom;
|
||||||
|
@ -210,6 +228,11 @@ public class CustomPersister implements EntityPersister {
|
||||||
( ( Custom ) entity ).id = ( String ) currentId;
|
( ( Custom ) entity ).id = ( String ) currentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resetIdentifier(Object entity, Serializable currentId, Object currentVersion, SessionImplementor session) {
|
||||||
|
checkEntityMode( session );
|
||||||
|
( ( Custom ) entity ).id = ( String ) currentId;
|
||||||
|
}
|
||||||
|
|
||||||
public EntityPersister getSubclassEntityPersister(Object instance, SessionFactoryImplementor factory, EntityMode entityMode) {
|
public EntityPersister getSubclassEntityPersister(Object instance, SessionFactoryImplementor factory, EntityMode entityMode) {
|
||||||
checkEntityMode( entityMode );
|
checkEntityMode( entityMode );
|
||||||
return this;
|
return this;
|
||||||
|
|
Loading…
Reference in New Issue