use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class FetchProfileTest method testWrongClass.
@Test
public void testWrongClass() {
final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Customer3.class).addAnnotatedClass(Order.class).addAnnotatedClass(Country.class);
try {
metadataSources.buildMetadata();
fail();
} catch (MappingException e) {
log.trace("success");
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class FetchProfileTest method testUnsupportedFetchMode.
@Test
public void testUnsupportedFetchMode() {
final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Customer4.class).addAnnotatedClass(Order.class).addAnnotatedClass(Country.class);
try {
metadataSources.buildMetadata();
fail();
} catch (MappingException e) {
log.trace("success");
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class PersistentClassTest method testGetProperty.
@Test
public void testGetProperty() {
RootClass pc = new RootClass(metadataBuildingContext);
Property p = new Property();
p.setName("name");
pc.addProperty(p);
Assert.assertEquals(p, pc.getProperty("name"));
Assert.assertEquals(p, pc.getProperty("name.test"));
try {
Assert.assertNull(pc.getProperty("test"));
Assert.fail("MappingException expected");
} catch (MappingException e) {
// expected
}
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class PathExpressionParser method token.
public void token(String token, QueryTranslatorImpl q) throws QueryException {
if (token != null) {
path.append(token);
}
String alias = q.getPathAlias(path.toString());
if (alias != null) {
//reset the dotcount (but not the path)
reset(q);
//afterQuery reset!
currentName = alias;
currentPropertyMapping = q.getPropertyMapping(currentName);
if (!ignoreInitialJoin) {
JoinSequence ojf = q.getPathJoin(path.toString());
try {
//afterQuery reset!
joinSequence.addCondition(ojf.toJoinFragment(q.getEnabledFilters(), true).toWhereFragmentString());
} catch (MappingException me) {
throw new QueryException(me);
}
// we don't need to worry about any condition in the ON clause
// here (toFromFragmentString), since anything in the ON condition
// is already applied to the whole query
}
} else if (".".equals(token)) {
dotcount++;
} else {
if (dotcount == 0) {
if (!continuation) {
if (!q.isName(token)) {
throw new QueryException("undefined alias: " + token);
}
currentName = token;
currentPropertyMapping = q.getPropertyMapping(currentName);
}
} else if (dotcount == 1) {
if (currentName != null) {
currentProperty = token;
} else if (collectionName != null) {
//processCollectionProperty(token, q.getCollectionPersister(collectionRole), collectionName);
continuation = false;
} else {
throw new QueryException("unexpected");
}
} else {
// dotcount>=2
// Do the corresponding RHS
Type propertyType = getPropertyType();
if (propertyType == null) {
throw new QueryException("unresolved property: " + path);
}
if (propertyType.isComponentType()) {
dereferenceComponent(token);
} else if (propertyType.isEntityType()) {
if (!isCollectionValued()) {
dereferenceEntity(token, (EntityType) propertyType, q);
}
} else if (propertyType.isCollectionType()) {
dereferenceCollection(token, ((CollectionType) propertyType).getRole(), q);
} else {
if (token != null) {
throw new QueryException("dereferenced: " + path);
}
}
}
}
}
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;
}
Aggregations