use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class DefaultIdentifierGeneratorFactory method getIdentifierGeneratorClass.
@Override
public Class getIdentifierGeneratorClass(String strategy) {
if ("hilo".equals(strategy)) {
throw new UnsupportedOperationException("Support for 'hilo' generator has been removed");
}
String resolvedStrategy = "native".equals(strategy) ? getDialect().getNativeIdentifierGeneratorStrategy() : strategy;
Class generatorClass = generatorStrategyToClassNameMap.get(resolvedStrategy);
try {
if (generatorClass == null) {
final ClassLoaderService cls = serviceRegistry.getService(ClassLoaderService.class);
generatorClass = cls.classForName(resolvedStrategy);
}
} catch (ClassLoadingException e) {
throw new MappingException(String.format("Could not interpret id generator strategy [%s]", strategy));
}
return generatorClass;
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class SessionImpl method find.
@Override
public <T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockModeType, Map<String, Object> properties) {
checkOpen();
LockOptions lockOptions = null;
try {
if (properties != null && !properties.isEmpty()) {
getLoadQueryInfluencers().setFetchGraph((EntityGraph) properties.get(QueryHints.HINT_FETCHGRAPH));
getLoadQueryInfluencers().setLoadGraph((EntityGraph) properties.get(QueryHints.HINT_LOADGRAPH));
}
final IdentifierLoadAccess<T> loadAccess = byId(entityClass);
loadAccess.with(determineAppropriateLocalCacheMode(properties));
if (lockModeType != null) {
if (!LockModeType.NONE.equals(lockModeType)) {
checkTransactionNeeded();
}
lockOptions = buildLockOptions(lockModeType, properties);
loadAccess.with(lockOptions);
}
return loadAccess.load((Serializable) primaryKey);
} catch (EntityNotFoundException ignored) {
// which find() should not throw. Find() should return null if the entity was not found.
if (log.isDebugEnabled()) {
String entityName = entityClass != null ? entityClass.getName() : null;
String identifierValue = primaryKey != null ? primaryKey.toString() : null;
log.ignoringEntityNotFound(entityName, identifierValue);
}
return null;
} catch (ObjectDeletedException e) {
//the spec is silent about people doing remove() find() on the same PC
return null;
} catch (ObjectNotFoundException e) {
//should not happen on the entity itself with get
throw new IllegalArgumentException(e.getMessage(), e);
} catch (MappingException | TypeMismatchException | ClassCastException e) {
throw exceptionConverter.convert(new IllegalArgumentException(e.getMessage(), e));
} catch (RuntimeException e) {
throw exceptionConverter.convert(e, lockOptions);
} finally {
getLoadQueryInfluencers().setFetchGraph(null);
getLoadQueryInfluencers().setLoadGraph(null);
}
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class SessionImpl method fireMerge.
private Object fireMerge(MergeEvent event) {
try {
checkTransactionSynchStatus();
checkNoUnresolvedActionsBeforeOperation();
for (MergeEventListener listener : listeners(EventType.MERGE)) {
listener.onMerge(event);
}
checkNoUnresolvedActionsAfterOperation();
} catch (ObjectDeletedException sse) {
throw exceptionConverter.convert(new IllegalArgumentException(sse));
} catch (MappingException e) {
throw exceptionConverter.convert(new IllegalArgumentException(e.getMessage(), e));
} catch (RuntimeException e) {
//including HibernateException
throw exceptionConverter.convert(e);
}
return event.getResult();
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class SessionImpl method refresh.
@Override
public void refresh(Object entity, LockModeType lockModeType, Map<String, Object> properties) {
checkOpen();
final CacheMode previousCacheMode = getCacheMode();
final CacheMode refreshCacheMode = determineAppropriateLocalCacheMode(properties);
LockOptions lockOptions = null;
try {
setCacheMode(refreshCacheMode);
if (!contains(entity)) {
throw exceptionConverter.convert(new IllegalArgumentException("Entity not managed"));
}
if (lockModeType != null) {
if (!LockModeType.NONE.equals(lockModeType)) {
checkTransactionNeeded();
}
lockOptions = buildLockOptions(lockModeType, properties);
refresh(entity, lockOptions);
} else {
refresh(entity);
}
} catch (MappingException e) {
throw exceptionConverter.convert(new IllegalArgumentException(e.getMessage(), e));
} catch (RuntimeException e) {
throw exceptionConverter.convert(e, lockOptions);
} finally {
setCacheMode(previousCacheMode);
}
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class AbstractPropertyMapping method initPropertyPaths.
/*protected void initPropertyPaths(
final String path,
final Type type,
final String[] columns,
final String[] formulaTemplates,
final Mapping factory)
throws MappingException {
//addFormulaPropertyPath(path, type, formulaTemplates);
initPropertyPaths(path, type, columns, formulaTemplates, factory);
}*/
protected void initPropertyPaths(final String path, final Type type, String[] columns, String[] columnReaders, String[] columnReaderTemplates, final String[] formulaTemplates, final Mapping factory) throws MappingException {
assert columns != null : "Incoming columns should not be null : " + path;
assert type != null : "Incoming type should not be null : " + path;
if (columns.length != type.getColumnSpan(factory)) {
throw new MappingException("broken column mapping for: " + path + " of: " + getEntityName());
}
if (type.isAssociationType()) {
AssociationType actype = (AssociationType) type;
if (actype.useLHSPrimaryKey()) {
columns = getIdentifierColumnNames();
columnReaders = getIdentifierColumnReaders();
columnReaderTemplates = getIdentifierColumnReaderTemplates();
} else {
String foreignKeyProperty = actype.getLHSPropertyName();
if (foreignKeyProperty != null && !path.equals(foreignKeyProperty)) {
//TODO: this requires that the collection is defined afterQuery the
// referenced property in the mapping file (ok?)
columns = columnsByPropertyPath.get(foreignKeyProperty);
if (columns == null) {
//get em on the second pass!
return;
}
columnReaders = columnReadersByPropertyPath.get(foreignKeyProperty);
columnReaderTemplates = columnReaderTemplatesByPropertyPath.get(foreignKeyProperty);
}
}
}
if (path != null) {
addPropertyPath(path, type, columns, columnReaders, columnReaderTemplates, formulaTemplates);
}
if (type.isComponentType()) {
CompositeType actype = (CompositeType) type;
initComponentPropertyPaths(path, actype, columns, columnReaders, columnReaderTemplates, formulaTemplates, factory);
if (actype.isEmbedded()) {
initComponentPropertyPaths(path == null ? null : StringHelper.qualifier(path), actype, columns, columnReaders, columnReaderTemplates, formulaTemplates, factory);
}
} else if (type.isEntityType()) {
initIdentifierPropertyPaths(path, (EntityType) type, columns, columnReaders, columnReaderTemplates, factory);
}
}
Aggregations