use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class QueryTranslatorImpl method compile.
/**
* Compile the query (generate the SQL).
*
* @throws org.hibernate.MappingException Indicates problems resolving
* things referenced in the query.
* @throws org.hibernate.QueryException Generally some form of syntatic
* failure.
*/
private void compile() throws QueryException, MappingException {
LOG.trace("Compiling query");
try {
ParserHelper.parse(new PreprocessingParser(tokenReplacements), queryString, ParserHelper.HQL_SEPARATORS, this);
renderSQL();
} catch (QueryException qe) {
if (qe.getQueryString() == null) {
throw qe.wrapWithQueryString(queryString);
} else {
throw qe;
}
} catch (MappingException me) {
throw me;
} catch (Exception e) {
LOG.debug("Unexpected query compilation problem", e);
e.printStackTrace();
throw new QueryException("Incorrect query syntax", queryString, e);
}
postInstantiate();
compiled = true;
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class PathExpressionParser method dereferenceEntity.
private void dereferenceEntity(String propertyName, EntityType propertyType, QueryTranslatorImpl q) throws QueryException {
//NOTE: we avoid joining to the next table if the named property is just the foreign key value
//if its "id"
boolean isIdShortcut = EntityPersister.ENTITY_ID.equals(propertyName) && propertyType.isReferenceToPrimaryKey();
//or its the id property name
final String idPropertyName;
try {
idPropertyName = propertyType.getIdentifierOrUniqueKeyPropertyName(q.getFactory());
} catch (MappingException me) {
throw new QueryException(me);
}
boolean isNamedIdPropertyShortcut = idPropertyName != null && idPropertyName.equals(propertyName) && propertyType.isReferenceToPrimaryKey();
if (isIdShortcut || isNamedIdPropertyShortcut) {
// this must only occur at the _end_ of a path expression
if (componentPath.length() > 0) {
componentPath.append('.');
}
componentPath.append(propertyName);
} else {
String entityClass = propertyType.getAssociatedEntityName();
String name = q.createNameFor(entityClass);
q.addType(name, entityClass);
addJoin(name, propertyType);
if (propertyType.isOneToOne()) {
oneToOneOwnerName = currentName;
}
ownerAssociationType = propertyType;
currentName = name;
currentProperty = propertyName;
q.addPathAliasAndJoin(path.substring(0, path.toString().lastIndexOf('.')), name, joinSequence.copy());
componentPath.setLength(0);
currentPropertyMapping = q.getEntityPersister(entityClass);
}
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class WhereParser method token.
public void token(String token, QueryTranslatorImpl q) throws QueryException {
String lcToken = token.toLowerCase(Locale.ROOT);
//Cope with [,]
if (token.equals("[") && !expectingPathContinuation) {
expectingPathContinuation = false;
if (expectingIndex == 0) {
throw new QueryException("unexpected [");
}
return;
} else if (token.equals("]")) {
expectingIndex--;
expectingPathContinuation = true;
return;
}
//Cope with a continued path expression (ie. ].baz)
if (expectingPathContinuation) {
boolean pathExpressionContinuesFurther = continuePathExpression(token, q);
if (pathExpressionContinuesFurther) {
//NOTE: early return
return;
}
}
//Cope with a subselect
if (!inSubselect && (lcToken.equals("select") || lcToken.equals("from"))) {
inSubselect = true;
subselect = new StringBuilder(20);
}
if (inSubselect && token.equals(")")) {
bracketsSinceSelect--;
if (bracketsSinceSelect == -1) {
QueryTranslatorImpl subq = new QueryTranslatorImpl(subselect.toString(), q.getEnabledFilters(), q.getFactory());
try {
subq.compile(q);
} catch (MappingException me) {
throw new QueryException("MappingException occurred compiling subquery", me);
}
appendToken(q, subq.getSQLString());
inSubselect = false;
bracketsSinceSelect = 0;
}
}
if (inSubselect) {
if (token.equals("(")) {
bracketsSinceSelect++;
}
subselect.append(token).append(' ');
return;
}
//Cope with special cases of AND, NOT, ()
specialCasesBefore(lcToken);
//Close extra brackets we opened
if (!betweenSpecialCase && EXPRESSION_TERMINATORS.contains(lcToken)) {
closeExpression(q, lcToken);
}
//take note when this is a boolean expression
if (BOOLEAN_OPERATORS.contains(lcToken)) {
booleanTests.removeLast();
booleanTests.addLast(Boolean.TRUE);
}
if (lcToken.equals("not")) {
nots.addLast(!(nots.removeLast()));
negated = !negated;
//NOTE: early return
return;
}
//process a token, mapping OO path expressions to SQL expressions
doToken(token, q);
//Open any extra brackets we might need.
if (!betweenSpecialCase && EXPRESSION_OPENERS.contains(lcToken)) {
openExpression(q, lcToken);
}
//Cope with special cases of AND, NOT, )
specialCasesAfter(lcToken);
}
use of org.hibernate.MappingException 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.MappingException in project hibernate-orm by hibernate.
the class SessionImpl method firePersist.
private void firePersist(PersistEvent event) {
try {
checkTransactionSynchStatus();
checkNoUnresolvedActionsBeforeOperation();
for (PersistEventListener listener : listeners(EventType.PERSIST)) {
listener.onPersist(event);
}
} catch (MappingException e) {
throw exceptionConverter.convert(new IllegalArgumentException(e.getMessage()));
} catch (RuntimeException e) {
throw exceptionConverter.convert(e);
} finally {
try {
checkNoUnresolvedActionsAfterOperation();
} catch (RuntimeException e) {
throw exceptionConverter.convert(e);
}
}
}
Aggregations