use of org.hibernate.HibernateException in project hibernate-orm by hibernate.
the class OnLockVisitor method processCollection.
@Override
public Object processCollection(Object collection, CollectionType type) throws HibernateException {
if (collection == null) {
return null;
}
final SessionImplementor session = getSession();
final CollectionPersister persister = session.getFactory().getCollectionPersister(type.getRole());
if (collection instanceof PersistentCollection) {
final PersistentCollection persistentCollection = (PersistentCollection) collection;
if (persistentCollection.setCurrentSession(session)) {
if (isOwnerUnchanged(persistentCollection, persister, extractCollectionKeyFromOwner(persister))) {
// a "detached" collection that originally belonged to the same entity
if (persistentCollection.isDirty()) {
throw new HibernateException("reassociated object has dirty collection");
}
reattachCollection(persistentCollection, type);
} else {
// a "detached" collection that belonged to a different entity
throw new HibernateException("reassociated object has dirty collection reference");
}
} else {
// to the entity passed to update()
throw new HibernateException("reassociated object has dirty collection reference");
}
} else {
//TODO: or an array!! we can't lock objects with arrays now??
throw new HibernateException("reassociated object has dirty collection reference (or an array)");
}
return null;
}
use of org.hibernate.HibernateException in project hibernate-orm by hibernate.
the class FilterImpl method setParameterList.
/**
* Set the named parameter's value list for this filter. Used
* in conjunction with IN-style filter criteria.
*
* @param name The parameter's name.
* @param values The values to be expanded into an SQL IN list.
* @return This FilterImpl instance (for method chaining).
*/
public Filter setParameterList(String name, Collection values) throws HibernateException {
// Make sure this is a defined parameter and check the incoming value type
if (values == null) {
throw new IllegalArgumentException("Collection must be not null!");
}
Type type = definition.getParameterType(name);
if (type == null) {
throw new HibernateException("Undefined filter parameter [" + name + "]");
}
if (!values.isEmpty()) {
Class elementClass = values.iterator().next().getClass();
if (!type.getReturnedClass().isAssignableFrom(elementClass)) {
throw new HibernateException("Incorrect type for parameter [" + name + "]");
}
}
parameters.put(name, values);
return this;
}
use of org.hibernate.HibernateException in project hibernate-orm by hibernate.
the class GUIDGenerator method generate.
public Serializable generate(SharedSessionContractImplementor session, Object obj) throws HibernateException {
final String sql = session.getJdbcServices().getJdbcEnvironment().getDialect().getSelectGUIDString();
try {
PreparedStatement st = session.getJdbcCoordinator().getStatementPreparer().prepareStatement(sql);
try {
ResultSet rs = session.getJdbcCoordinator().getResultSetReturn().extract(st);
final String result;
try {
if (!rs.next()) {
throw new HibernateException("The database returned no GUID identity value");
}
result = rs.getString(1);
} finally {
session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release(rs, st);
}
LOG.guidGenerated(result);
return result;
} finally {
session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release(st);
session.getJdbcCoordinator().afterStatementExecution();
}
} catch (SQLException sqle) {
throw session.getJdbcServices().getSqlExceptionHelper().convert(sqle, "could not retrieve GUID", sql);
}
}
use of org.hibernate.HibernateException in project hibernate-orm by hibernate.
the class UUIDGenerator method configure.
@Override
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
// check first for the strategy instance
strategy = (UUIDGenerationStrategy) params.get(UUID_GEN_STRATEGY);
if (strategy == null) {
// next check for the strategy class
final String strategyClassName = params.getProperty(UUID_GEN_STRATEGY_CLASS);
if (strategyClassName != null) {
try {
final ClassLoaderService cls = serviceRegistry.getService(ClassLoaderService.class);
final Class strategyClass = cls.classForName(strategyClassName);
try {
strategy = (UUIDGenerationStrategy) strategyClass.newInstance();
} catch (Exception ignore) {
LOG.unableToInstantiateUuidGenerationStrategy(ignore);
}
} catch (ClassLoadingException ignore) {
LOG.unableToLocateUuidGenerationStrategy(strategyClassName);
}
}
}
if (strategy == null) {
// lastly use the standard random generator
strategy = StandardRandomStrategy.INSTANCE;
}
if (UUID.class.isAssignableFrom(type.getReturnedClass())) {
valueTransformer = UUIDTypeDescriptor.PassThroughTransformer.INSTANCE;
} else if (String.class.isAssignableFrom(type.getReturnedClass())) {
valueTransformer = UUIDTypeDescriptor.ToStringTransformer.INSTANCE;
} else if (byte[].class.isAssignableFrom(type.getReturnedClass())) {
valueTransformer = UUIDTypeDescriptor.ToBytesTransformer.INSTANCE;
} else {
throw new HibernateException("Unanticipated return type [" + type.getReturnedClass().getName() + "] for UUID conversion");
}
}
use of org.hibernate.HibernateException in project hibernate-orm by hibernate.
the class SessionImpl method doFlush.
private void doFlush() {
checkTransactionNeeded();
checkTransactionSynchStatus();
try {
if (persistenceContext.getCascadeLevel() > 0) {
throw new HibernateException("Flush during cascade is dangerous");
}
FlushEvent flushEvent = new FlushEvent(this);
for (FlushEventListener listener : listeners(EventType.FLUSH)) {
listener.onFlush(flushEvent);
}
delayedAfterCompletion();
} catch (RuntimeException e) {
throw exceptionConverter.convert(e);
}
}
Aggregations