@Override public Serializable disassemble( Object value, SharedSessionContractImplementor session, Object owner) throws HibernateException { if ( value == null ) { return null; } else { // cache the actual id of the object, not the value of the // property-ref, which might not be initialized Object id = ForeignKeys.getEntityIdentifierIfNotUnsaved( getAssociatedEntityName(), value, session ); if ( id == null ) { throw new AssertionFailure( "cannot cache a reference to an object with a null id: " + getAssociatedEntityName() ); } return getIdentifierType( session ).disassemble( id, session, owner ); } }
Type type = q.getReturnTypes()[0]; assertTrue( type instanceof ManyToOneType ); assertEquals( ( (ManyToOneType) type ).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo" ); zoo = (Zoo) q.list().get(0); assertEquals( zoo.getMammals().size(), 1 );
Type type = q.getReturnTypes()[0]; assertTrue( type instanceof ManyToOneType ); assertEquals( ( (ManyToOneType) type ).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo" ); zoo = (Zoo) q .iterate().next();
Type type = q.getReturnTypes()[0]; assertTrue( type instanceof ManyToOneType ); assertEquals( ( (ManyToOneType) type ).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo" ); List<Zoo> zoos = (List<Zoo>) q.list(); assertEquals( 2, zoos.size() );
Type type = q.getReturnTypes()[0]; assertTrue( type instanceof ManyToOneType ); assertEquals( ( (ManyToOneType) type ).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo" ); List<Zoo> zoos = (List<Zoo>) q.list(); assertEquals( 3, zoos.size() );
/** * Construct a entity collection. * * @param parentMetadata parent meta data * @param childMetadata child meta data * @param parent parent object * @param objects child objects */ public HibernateEntityCollection(ClassMetadata parentMetadata, ClassMetadata childMetadata, Object parent, Collection<?> objects) { this.objects = objects; int i = 0; for (Type type : childMetadata.getPropertyTypes()) { if (type instanceof ManyToOneType) { ManyToOneType mto = (ManyToOneType) type; if (mto.getAssociatedEntityName().equals(parentMetadata.getEntityName())) { parentName = childMetadata.getPropertyNames()[i]; } } i++; } this.metadata = childMetadata; this.parent = parent; }
public Serializable disassemble(Object value, SessionImplementor session, Object owner) throws HibernateException { if ( isNotEmbedded(session) ) { return getIdentifierType(session).disassemble(value, session, owner); } if (value==null) { return null; } else { // cache the actual id of the object, not the value of the // property-ref, which might not be initialized Object id = ForeignKeys.getEntityIdentifierIfNotUnsaved( getAssociatedEntityName(), value, session ); if (id==null) { throw new AssertionFailure( "cannot cache a reference to an object with a null id: " + getAssociatedEntityName() ); } return getIdentifierType(session).disassemble(id, session, owner); } }
public Serializable disassemble( Object value, SessionImplementor session, Object owner) throws HibernateException { if ( isNotEmbedded( session ) ) { return getIdentifierType( session ).disassemble( value, session, owner ); } if ( value == null ) { return null; } else { // cache the actual id of the object, not the value of the // property-ref, which might not be initialized Object id = ForeignKeys.getEntityIdentifierIfNotUnsaved( getAssociatedEntityName(), value, session ); if ( id == null ) { throw new AssertionFailure( "cannot cache a reference to an object with a null id: " + getAssociatedEntityName() ); } return getIdentifierType( session ).disassemble( id, session, owner ); } }
public Serializable disassemble( Object value, SessionImplementor session, Object owner) throws HibernateException { if ( isNotEmbedded( session ) ) { return getIdentifierType( session ).disassemble( value, session, owner ); } if ( value == null ) { return null; } else { // cache the actual id of the object, not the value of the // property-ref, which might not be initialized Object id = ForeignKeys.getEntityIdentifierIfNotUnsaved( getAssociatedEntityName(), value, session ); if ( id == null ) { throw new AssertionFailure( "cannot cache a reference to an object with a null id: " + getAssociatedEntityName() ); } return getIdentifierType( session ).disassemble( id, session, owner ); } }
/** * Register the entity as batch loadable, if enabled */ private void scheduleBatchLoad(Serializable id, SessionImplementor session) throws MappingException { if (uniqueKeyPropertyName==null) { //cannot batch fetch by unique key EntityPersister persister = session.getFactory() .getEntityPersister( getAssociatedEntityName() ); session.getPersistenceContext() .getBatchFetchQueue() .addBatchLoadableEntityKey( new EntityKey( id, persister, session.getEntityMode() ) ); } }
/** * Register the entity as batch loadable, if enabled */ @SuppressWarnings({ "JavaDoc" }) private void scheduleBatchLoadIfNeeded(Serializable id, SessionImplementor session) throws MappingException { //cannot batch fetch by unique key (property-ref associations) if ( uniqueKeyPropertyName == null && id != null ) { final EntityPersister persister = session.getFactory().getEntityPersister( getAssociatedEntityName() ); final EntityKey entityKey = session.generateEntityKey( id, persister ); if ( !session.getPersistenceContext().containsEntity( entityKey ) ) { session.getPersistenceContext().getBatchFetchQueue().addBatchLoadableEntityKey( entityKey ); } } }
/** * Register the entity as batch loadable, if enabled */ @SuppressWarnings({ "JavaDoc" }) private void scheduleBatchLoadIfNeeded(Serializable id, SessionImplementor session) throws MappingException { //cannot batch fetch by unique key (property-ref associations) if ( uniqueKeyPropertyName == null && id != null ) { final EntityPersister persister = session.getFactory().getEntityPersister( getAssociatedEntityName() ); final EntityKey entityKey = session.generateEntityKey( id, persister ); if ( !session.getPersistenceContext().containsEntity( entityKey ) ) { session.getPersistenceContext().getBatchFetchQueue().addBatchLoadableEntityKey( entityKey ); } } }
if (t instanceof ManyToOneType) { ManyToOneType manyToOneType = (ManyToOneType) t; AbstractEntityPersister persister = (AbstractEntityPersister) session.getFactory().getEntityPersister(manyToOneType.getAssociatedEntityName());
EntityPersister persister = session.getFactory().getEntityPersister( getAssociatedEntityName() ); EntityKey entityKey = new EntityKey( id, persister, session.getEntityMode() ); if ( !session.getPersistenceContext().containsEntity( entityKey ) ) {