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));
}
}
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations