Search in sources :

Example 61 with HibernateException

use of org.hibernate.HibernateException in project hibernate-orm by hibernate.

the class Table method validateColumns.

public void validateColumns(Dialect dialect, Mapping mapping, TableMetadata tableInfo) {
    Iterator iter = getColumnIterator();
    while (iter.hasNext()) {
        Column col = (Column) iter.next();
        ColumnMetadata columnInfo = tableInfo.getColumnMetadata(col.getName());
        if (columnInfo == null) {
            throw new HibernateException("Missing column: " + col.getName() + " in " + Table.qualify(tableInfo.getCatalog(), tableInfo.getSchema(), tableInfo.getName()));
        } else {
            final boolean typesMatch = col.getSqlType(dialect, mapping).toLowerCase(Locale.ROOT).startsWith(columnInfo.getTypeName().toLowerCase(Locale.ROOT)) || columnInfo.getTypeCode() == col.getSqlTypeCode(mapping);
            if (!typesMatch) {
                throw new HibernateException("Wrong column type in " + Table.qualify(tableInfo.getCatalog(), tableInfo.getSchema(), tableInfo.getName()) + " for column " + col.getName() + ". Found: " + columnInfo.getTypeName().toLowerCase(Locale.ROOT) + ", expected: " + col.getSqlType(dialect, mapping));
            }
        }
    }
}
Also used : ColumnMetadata(org.hibernate.tool.hbm2ddl.ColumnMetadata) HibernateException(org.hibernate.HibernateException) Iterator(java.util.Iterator)

Example 62 with HibernateException

use of org.hibernate.HibernateException in project hibernate-orm by hibernate.

the class Constraint method hashedName.

/**
	 * Hash a constraint name using MD5. Convert the MD5 digest to base 35
	 * (full alphanumeric), guaranteeing
	 * that the length of the name will always be smaller than the 30
	 * character identifier restriction enforced by a few dialects.
	 * 
	 * @param s
	 *            The name to be hashed.
	 * @return String The hased name.
	 */
public static String hashedName(String s) {
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.reset();
        md.update(s.getBytes());
        byte[] digest = md.digest();
        BigInteger bigInt = new BigInteger(1, digest);
        // character identifier restriction enforced by a few dialects.
        return bigInt.toString(35);
    } catch (NoSuchAlgorithmException e) {
        throw new HibernateException("Unable to generate a hashed Constraint name!", e);
    }
}
Also used : HibernateException(org.hibernate.HibernateException) BigInteger(java.math.BigInteger) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Example 63 with HibernateException

use of org.hibernate.HibernateException in project hibernate-orm by hibernate.

the class ByteBuddyProxyFactory method getProxy.

@Override
public HibernateProxy getProxy(Serializable id, SharedSessionContractImplementor session) throws HibernateException {
    final ByteBuddyInterceptor interceptor = new ByteBuddyInterceptor(entityName, persistentClass, interfaces, id, getIdentifierMethod, setIdentifierMethod, componentIdType, session, overridesEquals);
    try {
        final HibernateProxy proxy = (HibernateProxy) proxyClass.newInstance();
        ((ProxyConfiguration) proxy).$$_hibernate_set_interceptor(interceptor);
        return proxy;
    } catch (Throwable t) {
        LOG.error(LOG.bytecodeEnhancementFailed(entityName), t);
        throw new HibernateException(LOG.bytecodeEnhancementFailed(entityName), t);
    }
}
Also used : ProxyConfiguration(org.hibernate.proxy.ProxyConfiguration) HibernateException(org.hibernate.HibernateException) HibernateProxy(org.hibernate.proxy.HibernateProxy)

Example 64 with HibernateException

use of org.hibernate.HibernateException in project hibernate-orm by hibernate.

the class ByteBuddyProxyFactory method deserializeProxy.

public static HibernateProxy deserializeProxy(SerializableProxy serializableProxy) {
    final ByteBuddyInterceptor interceptor = new ByteBuddyInterceptor(serializableProxy.getEntityName(), serializableProxy.getPersistentClass(), serializableProxy.getInterfaces(), serializableProxy.getId(), resolveIdGetterMethod(serializableProxy), resolveIdSetterMethod(serializableProxy), serializableProxy.getComponentIdType(), null, ReflectHelper.overridesEquals(serializableProxy.getPersistentClass()));
    // note: interface is assumed to already contain HibernateProxy.class
    try {
        final Class proxyClass = buildProxy(serializableProxy.getPersistentClass(), serializableProxy.getInterfaces());
        final HibernateProxy proxy = (HibernateProxy) proxyClass.newInstance();
        ((ProxyConfiguration) proxy).$$_hibernate_set_interceptor(interceptor);
        return proxy;
    } catch (Throwable t) {
        final String message = LOG.bytecodeEnhancementFailed(serializableProxy.getEntityName());
        LOG.error(message, t);
        throw new HibernateException(message, t);
    }
}
Also used : ProxyConfiguration(org.hibernate.proxy.ProxyConfiguration) HibernateException(org.hibernate.HibernateException) HibernateProxy(org.hibernate.proxy.HibernateProxy)

Example 65 with HibernateException

use of org.hibernate.HibernateException 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)

Aggregations

HibernateException (org.hibernate.HibernateException)372 DAOException (org.jbei.ice.storage.DAOException)141 Session (org.hibernate.Session)72 Test (org.junit.Test)41 ArrayList (java.util.ArrayList)30 SQLException (java.sql.SQLException)27 IOException (java.io.IOException)15 TestForIssue (org.hibernate.testing.TestForIssue)15 Transaction (org.hibernate.Transaction)14 Group (org.jbei.ice.storage.model.Group)14 Type (org.hibernate.type.Type)12 PersistenceException (org.mifos.framework.exceptions.PersistenceException)12 Serializable (java.io.Serializable)11 EntityEntry (org.hibernate.engine.spi.EntityEntry)10 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)10 HashMap (java.util.HashMap)9 Method (java.lang.reflect.Method)8 Dialect (org.hibernate.dialect.Dialect)8 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)8 HibernateProxy (org.hibernate.proxy.HibernateProxy)8