Search in sources :

Example 1 with NonIdentifierAttribute

use of org.hibernate.tuple.NonIdentifierAttribute in project hibernate-orm by hibernate.

the class AbstractEntityPersister method processGeneratedProperties.

private void processGeneratedProperties(Serializable id, Object entity, Object[] state, SharedSessionContractImplementor session, String selectionSQL, GenerationTiming matchTiming) {
    // force immediate execution of the insert batch (if one)
    session.getJdbcCoordinator().executeBatch();
    try {
        PreparedStatement ps = session.getJdbcCoordinator().getStatementPreparer().prepareStatement(selectionSQL);
        try {
            getIdentifierType().nullSafeSet(ps, id, 1, session);
            ResultSet rs = session.getJdbcCoordinator().getResultSetReturn().extract(ps);
            try {
                if (!rs.next()) {
                    throw new HibernateException("Unable to locate row for retrieval of generated properties: " + MessageHelper.infoString(this, id, getFactory()));
                }
                int propertyIndex = -1;
                for (NonIdentifierAttribute attribute : entityMetamodel.getProperties()) {
                    propertyIndex++;
                    if (isValueGenerationRequired(attribute, matchTiming)) {
                        final Object hydratedState = attribute.getType().hydrate(rs, getPropertyAliases("", propertyIndex), session, entity);
                        state[propertyIndex] = attribute.getType().resolve(hydratedState, session, entity);
                        setPropertyValue(entity, propertyIndex, state[propertyIndex]);
                    }
                }
            //					for ( int i = 0; i < getPropertySpan(); i++ ) {
            //						if ( includeds[i] != ValueInclusion.NONE ) {
            //							Object hydratedState = getPropertyTypes()[i].hydrate( rs, getPropertyAliases( "", i ), session, entity );
            //							state[i] = getPropertyTypes()[i].resolve( hydratedState, session, entity );
            //							setPropertyValue( entity, i, state[i] );
            //						}
            //					}
            } finally {
                if (rs != null) {
                    session.getJdbcCoordinator().getResourceRegistry().release(rs, ps);
                }
            }
        } finally {
            session.getJdbcCoordinator().getResourceRegistry().release(ps);
            session.getJdbcCoordinator().afterStatementExecution();
        }
    } catch (SQLException e) {
        throw getFactory().getSQLExceptionHelper().convert(e, "unable to select generated column values", selectionSQL);
    }
}
Also used : HibernateException(org.hibernate.HibernateException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) NonIdentifierAttribute(org.hibernate.tuple.NonIdentifierAttribute)

Example 2 with NonIdentifierAttribute

use of org.hibernate.tuple.NonIdentifierAttribute in project hibernate-orm by hibernate.

the class LazyBasicFieldNotInitializedTestTask method execute.

public void execute() {
    Session s = getFactory().openSession();
    s.beginTransaction();
    Entity entity = s.get(Entity.class, entityId);
    Assert.assertFalse(Hibernate.isPropertyInitialized(entity, "description"));
    final EntityMetamodel entityMetamodel = ((SessionFactoryImplementor) getFactory()).getEntityPersister(Entity.class.getName()).getEntityMetamodel();
    final boolean[] propertyLaziness = entityMetamodel.getPropertyLaziness();
    assertEquals(1, propertyLaziness.length);
    assertTrue(propertyLaziness[0]);
    // Make sure NonIdentifierAttribute#isLazy is consistent (HHH-10551)
    final NonIdentifierAttribute[] properties = entityMetamodel.getProperties();
    assertEquals(1, properties.length);
    assertTrue(properties[0].isLazy());
    s.getTransaction().commit();
    s.close();
}
Also used : NonIdentifierAttribute(org.hibernate.tuple.NonIdentifierAttribute) EntityMetamodel(org.hibernate.tuple.entity.EntityMetamodel) Session(org.hibernate.Session)

Example 3 with NonIdentifierAttribute

use of org.hibernate.tuple.NonIdentifierAttribute in project hibernate-orm by hibernate.

the class AbstractEntityTuplizer method getPropertyValues.

@Override
public Object[] getPropertyValues(Object entity) {
    final BytecodeEnhancementMetadata enhancementMetadata = entityMetamodel.getBytecodeEnhancementMetadata();
    final int span = entityMetamodel.getPropertySpan();
    final Object[] result = new Object[span];
    for (int j = 0; j < span; j++) {
        NonIdentifierAttribute property = entityMetamodel.getProperties()[j];
        if (!property.isLazy() || enhancementMetadata.isAttributeLoaded(entity, property.getName())) {
            result[j] = getters[j].get(entity);
        } else {
            result[j] = LazyPropertyInitializer.UNFETCHED_PROPERTY;
        }
    }
    return result;
}
Also used : NonIdentifierAttribute(org.hibernate.tuple.NonIdentifierAttribute) BytecodeEnhancementMetadata(org.hibernate.bytecode.spi.BytecodeEnhancementMetadata)

Aggregations

NonIdentifierAttribute (org.hibernate.tuple.NonIdentifierAttribute)3 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 HibernateException (org.hibernate.HibernateException)1 Session (org.hibernate.Session)1 BytecodeEnhancementMetadata (org.hibernate.bytecode.spi.BytecodeEnhancementMetadata)1 EntityMetamodel (org.hibernate.tuple.entity.EntityMetamodel)1