@Override public Object instantiate(Object parent, SharedSessionContractImplementor session) throws HibernateException { final boolean useParent = parent != null && //TODO: Yuck! This is not quite good enough, it's a quick //hack around the problem of having a to-one association //that refers to an embedded component: super.getReturnedClass().isInstance( parent ); return useParent ? parent : super.instantiate( parent, session ); } }
@Override public Object getIdentifier(Object entity, EntityMode entityMode, SharedSessionContractImplementor session) { Object id = mappedIdentifierType.instantiate( entityMode ); final Object[] propertyValues = virtualIdComponent.getPropertyValues( entity, entityMode ); mappedIdentifierType.setPropertyValues( id, propertyValues, entityMode ); return id; }
@Override public Object resolve(Object value, SharedSessionContractImplementor session, Object owner) throws HibernateException { if ( value != null ) { Object result = instantiate( owner, session ); Object[] values = (Object[]) value; Object[] resolvedValues = new Object[values.length]; //only really need new array during semiresolve! for ( int i = 0; i < values.length; i++ ) { resolvedValues[i] = propertyTypes[i].resolve( values[i], session, owner ); } setPropertyValues( result, resolvedValues, entityMode ); return result; } else if ( isCreateEmptyCompositesEnabled() ) { return instantiate( owner, session ); } else { return null; } }
@Override public Object assemble(Serializable object, SharedSessionContractImplementor session, Object owner) throws HibernateException { if ( object == null ) { return null; } else { Object[] values = (Object[]) object; Object[] assembled = new Object[values.length]; for ( int i = 0; i < propertyTypes.length; i++ ) { assembled[i] = propertyTypes[i].assemble( (Serializable) values[i], session, owner ); } Object result = instantiate( owner, session ); setPropertyValues( result, assembled, entityMode ); return result; } }
public Object instantiate(Object parent, SharedSessionContractImplementor session) throws HibernateException { Object result = instantiate( entityMode ); if ( componentTuplizer.hasParentProperty() && parent != null ) { componentTuplizer.setParent( result, session.getPersistenceContext().proxyFor( parent ), session.getFactory() ); } return result; }
@Override public Object replace( Object original, Object target, SharedSessionContractImplementor session, Object owner, Map copyCache) throws HibernateException { if ( original == null ) { return null; } //if ( original == target ) return target; final Object result = target == null ? instantiate( owner, session ) : target; Object[] values = TypeHelper.replace( getPropertyValues( original, entityMode ), getPropertyValues( result, entityMode ), propertyTypes, session, owner, copyCache ); setPropertyValues( result, values, entityMode ); return result; }
@Override public Object deepCopy(Object component, SessionFactoryImplementor factory) throws HibernateException { if ( component == null ) { return null; } Object[] values = getPropertyValues( component, entityMode ); for ( int i = 0; i < propertySpan; i++ ) { values[i] = propertyTypes[i].deepCopy( values[i], factory ); } Object result = instantiate( entityMode ); setPropertyValues( result, values, entityMode ); //not absolutely necessary, but helps for some //equals()/hashCode() implementations if ( componentTuplizer.hasParentProperty() ) { componentTuplizer.setParent( result, componentTuplizer.getParent( component ), factory ); } return result; }
@Override public Object getIdentifier(Object entity, EntityMode entityMode, SharedSessionContractImplementor session) { final Object id = mappedIdentifierType.instantiate( entityMode ); final Object[] propertyValues = virtualIdComponent.getPropertyValues( entity, entityMode ); final Type[] subTypes = virtualIdComponent.getSubtypes(); final Type[] copierSubTypes = mappedIdentifierType.getSubtypes(); final int length = subTypes.length; for ( int i = 0; i < length; i++ ) { if ( propertyValues[i] == null ) { throw new HibernateException( "No part of a composite identifier may be null" ); } //JPA 2 @MapsId + @IdClass points to the pk of the entity if ( subTypes[i].isAssociationType() && !copierSubTypes[i].isAssociationType() ) { propertyValues[i] = determineEntityId( propertyValues[i], (AssociationType) subTypes[i], session, sessionFactory ); } } mappedIdentifierType.setPropertyValues( id, propertyValues, entityMode ); return id; }
instantiate( owner, session ) : target;
@Test @TestForIssue(jiraKey = "HHH-12791") public void testOnlyOneProxyClassGenerated() { StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); try { Metadata metadata = new MetadataSources( ssr ).addAnnotatedClass( Person.class ) .getMetadataBuilder().applyBasicType( new DelimitedStringsType() ) .build(); PersistentClass persistentClass = metadata.getEntityBinding( Person.class.getName() ); ComponentType componentType1 = (ComponentType) persistentClass.getIdentifierMapper().getType(); Object instance1 = componentType1.instantiate( EntityMode.POJO ); ComponentType componentType2 = (ComponentType) persistentClass.getIdentifierMapper().getType(); Object instance2 = componentType2.instantiate( EntityMode.POJO ); assertEquals( instance1.getClass(), instance2.getClass() ); } finally { StandardServiceRegistryBuilder.destroy( ssr ); } } }
public Object instantiate(Object parent, SessionImplementor session) throws HibernateException { final boolean useParent = parent!=null && //TODO: Yuck! This is not quite good enough, its a quick //hack around the problem of having a to-one association //that refers to an embedded component: super.getReturnedClass().isInstance(parent); return useParent ? parent : super.instantiate(parent, session); } }
public Object instantiate(Object parent, SessionImplementor session) throws HibernateException { final boolean useParent = parent!=null && //TODO: Yuck! This is not quite good enough, it's a quick //hack around the problem of having a to-one association //that refers to an embedded component: super.getReturnedClass().isInstance(parent); return useParent ? parent : super.instantiate(parent, session); } }
public Object instantiate(Object parent, SessionImplementor session) throws HibernateException { final boolean useParent = parent!=null && //TODO: Yuck! This is not quite good enough, it's a quick //hack around the problem of having a to-one association //that refers to an embedded component: super.getReturnedClass().isInstance(parent); return useParent ? parent : super.instantiate(parent, session); } }
public Object instantiate(Object parent, SessionImplementor session) throws HibernateException { final boolean useParent = parent!=null && //TODO: Yuck! This is not quite good enough, it's a quick //hack around the problem of having a to-one association //that refers to an embedded component: super.getReturnedClass().isInstance(parent); return useParent ? parent : super.instantiate(parent, session); } }
public Object getIdentifier(Object entity, EntityMode entityMode, SessionImplementor session) { Object id = mappedIdentifierType.instantiate( entityMode ); final Object[] propertyValues = virtualIdComponent.getPropertyValues( entity, entityMode ); mappedIdentifierType.setPropertyValues( id, propertyValues, entityMode ); return id; }
public Object getIdentifier(Object entity, EntityMode entityMode, SessionImplementor session) { Object id = mappedIdentifierType.instantiate( entityMode ); final Object[] propertyValues = virtualIdComponent.getPropertyValues( entity, entityMode ); mappedIdentifierType.setPropertyValues( id, propertyValues, entityMode ); return id; }
public Object resolve(Object value, SessionImplementor session, Object owner) throws HibernateException { if ( value != null ) { Object result = instantiate( owner, session ); Object[] values = ( Object[] ) value; Object[] resolvedValues = new Object[values.length]; //only really need new array during semiresolve! for ( int i = 0; i < values.length; i++ ) { resolvedValues[i] = propertyTypes[i].resolve( values[i], session, owner ); } setPropertyValues( result, resolvedValues, session.getEntityMode() ); return result; } else { return null; } }
public Object instantiate(Object parent, SessionImplementor session) throws HibernateException { Object result = instantiate( entityMode ); if ( componentTuplizer.hasParentProperty() && parent != null ) { componentTuplizer.setParent( result, session.getPersistenceContext().proxyFor( parent ), session.getFactory() ); } return result; }
public Object instantiate(Object parent, SessionImplementor session) throws HibernateException { Object result = instantiate( entityMode ); if ( componentTuplizer.hasParentProperty() && parent != null ) { componentTuplizer.setParent( result, session.getPersistenceContext().proxyFor( parent ), session.getFactory() ); } return result; }
public Object instantiate(Object parent, SessionImplementor session) throws HibernateException { Object result = instantiate( session.getEntityMode() ); ComponentTuplizer ct = (ComponentTuplizer) tuplizers.getTuplizer( session.getEntityMode() ); if ( ct.hasParentProperty() && parent != null ) { ct.setParent( result, session.getPersistenceContext().proxyFor( parent ), session.getFactory() ); } return result; }