Search in sources :

Example 6 with VersionType

use of org.hibernate.type.VersionType in project hibernate-orm by hibernate.

the class EntityReferenceInitializerImpl method checkVersion.

private void checkVersion(SharedSessionContractImplementor session, ResultSet resultSet, EntityPersister persister, EntityAliases entityAliases, EntityKey entityKey, Object entityInstance) {
    final Object version = session.getPersistenceContext().getEntry(entityInstance).getVersion();
    if (version != null) {
        //null version means the object is in the process of being loaded somewhere else in the ResultSet
        VersionType versionType = persister.getVersionType();
        final Object currentVersion;
        try {
            currentVersion = versionType.nullSafeGet(resultSet, entityAliases.getSuffixedVersionAliases(), session, null);
        } catch (SQLException e) {
            throw session.getFactory().getServiceRegistry().getService(JdbcServices.class).getSqlExceptionHelper().convert(e, "Could not read version value from result set");
        }
        if (!versionType.isEqual(version, currentVersion)) {
            if (session.getFactory().getStatistics().isStatisticsEnabled()) {
                session.getFactory().getStatistics().optimisticFailure(persister.getEntityName());
            }
            throw new StaleObjectStateException(persister.getEntityName(), entityKey.getIdentifier());
        }
    }
}
Also used : SQLException(java.sql.SQLException) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) StaleObjectStateException(org.hibernate.StaleObjectStateException) VersionType(org.hibernate.type.VersionType)

Aggregations

VersionType (org.hibernate.type.VersionType)6 AST (antlr.collections.AST)2 Session (org.hibernate.Session)2 StaleObjectStateException (org.hibernate.StaleObjectStateException)2 ParameterNode (org.hibernate.hql.internal.ast.tree.ParameterNode)2 CollectionFilterKeyParameterSpecification (org.hibernate.param.CollectionFilterKeyParameterSpecification)2 NamedParameterSpecification (org.hibernate.param.NamedParameterSpecification)2 ParameterSpecification (org.hibernate.param.ParameterSpecification)2 PositionalParameterSpecification (org.hibernate.param.PositionalParameterSpecification)2 VersionTypeSeedParameterSpecification (org.hibernate.param.VersionTypeSeedParameterSpecification)2 Queryable (org.hibernate.persister.entity.Queryable)2 TestForIssue (org.hibernate.testing.TestForIssue)2 RowVersionType (org.hibernate.type.RowVersionType)2 UserVersionType (org.hibernate.usertype.UserVersionType)2 Test (org.junit.Test)2 SemanticException (antlr.SemanticException)1 SQLException (java.sql.SQLException)1 QueryException (org.hibernate.QueryException)1 JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)1 FromClause (org.hibernate.hql.internal.ast.tree.FromClause)1