Java Code Examples for org.hibernate.persister.entity.EntityPersister#canExtractIdOutOfEntity()
The following examples show how to use
org.hibernate.persister.entity.EntityPersister#canExtractIdOutOfEntity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultReactiveFlushEntityEventListener.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 6 votes |
/** * make sure user didn't mangle the id */ public void checkId(Object object, EntityPersister persister, Serializable id, SessionImplementor session) throws HibernateException { if (id instanceof DelayedPostInsertIdentifier) { // this is a situation where the entity id is assigned by a post-insert generator // and was saved outside the transaction forcing it to be delayed return; } if ( persister.canExtractIdOutOfEntity() ) { Serializable oid = persister.getIdentifier( object, session ); if ( id == null ) { throw new AssertionFailure( "null id in " + persister.getEntityName() + " entry (don't flush the Session after an exception occurs)" ); } if ( !persister.getIdentifierType().isEqual( id, oid, session.getFactory() ) ) { throw new HibernateException( "identifier of an instance of " + persister.getEntityName() + " was altered from " + id + " to " + oid ); } } }
Example 2
Source File: DefaultFlushEntityEventListener.java From lams with GNU General Public License v2.0 | 6 votes |
/** * make sure user didn't mangle the id */ public void checkId(Object object, EntityPersister persister, Serializable id, SessionImplementor session) throws HibernateException { if ( id != null && id instanceof DelayedPostInsertIdentifier ) { // this is a situation where the entity id is assigned by a post-insert generator // and was saved outside the transaction forcing it to be delayed return; } if ( persister.canExtractIdOutOfEntity() ) { Serializable oid = persister.getIdentifier( object, session ); if ( id == null ) { throw new AssertionFailure( "null id in " + persister.getEntityName() + " entry (don't flush the Session after an exception occurs)" ); } if ( !persister.getIdentifierType().isEqual( id, oid, session.getFactory() ) ) { throw new HibernateException( "identifier of an instance of " + persister.getEntityName() + " was altered from " + id + " to " + oid ); } } }
Example 3
Source File: EntityType.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** * {@inheritDoc} */ public int getHashCode(Object x, EntityMode entityMode, SessionFactoryImplementor factory) { EntityPersister persister = factory.getEntityPersister(associatedEntityName); if ( !persister.canExtractIdOutOfEntity() ) { return super.getHashCode(x, entityMode); } final Serializable id; if (x instanceof HibernateProxy) { id = ( (HibernateProxy) x ).getHibernateLazyInitializer().getIdentifier(); } else { id = persister.getIdentifier(x, entityMode); } return persister.getIdentifierType().getHashCode(id, entityMode, factory); }
Example 4
Source File: DefaultFlushEntityEventListener.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * make sure user didn't mangle the id */ public void checkId(Object object, EntityPersister persister, Serializable id, EntityMode entityMode) throws HibernateException { if ( id != null && id instanceof DelayedPostInsertIdentifier ) { // this is a situation where the entity id is assigned by a post-insert generator // and was saved outside the transaction forcing it to be delayed return; } if ( persister.canExtractIdOutOfEntity() ) { Serializable oid = persister.getIdentifier( object, entityMode ); if (id==null) { throw new AssertionFailure("null id in " + persister.getEntityName() + " entry (don't flush the Session after an exception occurs)"); } if ( !persister.getIdentifierType().isEqual(id, oid, entityMode) ) { throw new HibernateException( "identifier of an instance of " + persister.getEntityName() + " was altered from " + id + " to " + oid ); } } }
Example 5
Source File: EntityType.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * {@inheritDoc} */ public boolean isEqual(Object x, Object y, EntityMode entityMode, SessionFactoryImplementor factory) { EntityPersister persister = factory.getEntityPersister(associatedEntityName); if ( !persister.canExtractIdOutOfEntity() ) { return super.isEqual(x, y, entityMode); } Serializable xid; if (x instanceof HibernateProxy) { xid = ( (HibernateProxy) x ).getHibernateLazyInitializer() .getIdentifier(); } else { xid = persister.getIdentifier(x, entityMode); } Serializable yid; if (y instanceof HibernateProxy) { yid = ( (HibernateProxy) y ).getHibernateLazyInitializer() .getIdentifier(); } else { yid = persister.getIdentifier(y, entityMode); } return persister.getIdentifierType() .isEqual(xid, yid, entityMode, factory); }