use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class QueryTranslatorTestCase method assertTranslation.
protected void assertTranslation(String hql, Map replacements, boolean scalar, String sql) {
SessionFactoryImplementor factory = sessionFactory();
// Create an empty replacements map if we don't have one.
if (replacements == null) {
replacements = new HashMap();
}
// steve -> note that the empty maps here represent the currently enabled filters...
QueryTranslator oldQueryTranslator = null;
Exception oldException = null;
try {
System.out.println("Compiling with classic QueryTranslator...");
QueryTranslatorFactory classic = new ClassicQueryTranslatorFactory();
oldQueryTranslator = classic.createQueryTranslator(hql, hql, Collections.EMPTY_MAP, factory, null);
oldQueryTranslator.compile(replacements, scalar);
} catch (QueryException e) {
oldException = e;
} catch (MappingException e) {
oldException = e;
}
QueryTranslator newQueryTranslator = null;
Exception newException = null;
try {
System.out.println("Compiling with AST QueryTranslator...");
newQueryTranslator = createNewQueryTranslator(hql, replacements, scalar);
} catch (QueryException e) {
newException = e;
} catch (MappingException e) {
newException = e;
}
// If the old QT threw an exception, the new one should too.
if (oldException != null) {
assertNotNull("New query translator did *NOT* throw an exception, the old one did : " + oldException, newException);
assertEquals(oldException.getMessage(), newException.getMessage());
// Don't bother with the rest of the assertions.
return;
} else if (newException != null) {
newException.printStackTrace();
assertNull("Old query translator did not throw an exception, the new one did", newException);
}
// -- check all of the outputs --
checkSql(oldQueryTranslator, newQueryTranslator, hql, scalar, sql);
checkQuerySpaces(oldQueryTranslator, newQueryTranslator);
checkReturnedTypes(oldQueryTranslator, newQueryTranslator);
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class QueryTranslatorTestCase method compileBadHql.
protected Exception compileBadHql(String hql, boolean scalar) {
QueryTranslator newQueryTranslator;
Map replacements = null;
Exception newException = null;
SessionFactoryImplementor factory = sessionFactory();
try {
QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
newQueryTranslator = ast.createQueryTranslator(hql, hql, Collections.EMPTY_MAP, factory, null);
newQueryTranslator.compile(replacements, scalar);
} catch (QueryException e) {
newException = e;
} catch (MappingException e) {
newException = e;
}
assertNotNull("Expected exception from compilation of '" + hql + "'!", newException);
return newException;
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class AnnotationBinder method processJoinedDiscriminatorProperties.
/**
* Process all discriminator-related metadata per rules for "joined" inheritance
*/
private static Ejb3DiscriminatorColumn processJoinedDiscriminatorProperties(XClass clazzToProcess, MetadataBuildingContext context, InheritanceState inheritanceState, EntityBinder entityBinder) {
if (clazzToProcess.isAnnotationPresent(DiscriminatorFormula.class)) {
throw new MappingException("@DiscriminatorFormula on joined inheritance not supported at this time");
}
// DiscriminatorValue handling ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
final DiscriminatorValue discriminatorValueAnnotation = clazzToProcess.getAnnotation(DiscriminatorValue.class);
final String discriminatorValue = discriminatorValueAnnotation != null ? clazzToProcess.getAnnotation(DiscriminatorValue.class).value() : null;
entityBinder.setDiscriminatorValue(discriminatorValue);
// DiscriminatorColumn handling ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
final DiscriminatorColumn discriminatorColumnAnnotation = clazzToProcess.getAnnotation(DiscriminatorColumn.class);
if (!inheritanceState.hasParents()) {
// we want to process the discriminator column if either:
// 1) There is an explicit DiscriminatorColumn annotation && we are not told to ignore them
// 2) There is not an explicit DiscriminatorColumn annotation && we are told to create them implicitly
final boolean generateDiscriminatorColumn;
if (discriminatorColumnAnnotation != null) {
if (context.getBuildingOptions().ignoreExplicitDiscriminatorsForJoinedInheritance()) {
LOG.debugf("Ignoring explicit DiscriminatorColumn annotation on ", clazzToProcess.getName());
generateDiscriminatorColumn = false;
} else {
LOG.applyingExplicitDiscriminatorColumnForJoined(clazzToProcess.getName(), AvailableSettings.IGNORE_EXPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS);
generateDiscriminatorColumn = true;
}
} else {
if (context.getBuildingOptions().createImplicitDiscriminatorsForJoinedInheritance()) {
LOG.debug("Applying implicit DiscriminatorColumn using DiscriminatorColumn defaults");
generateDiscriminatorColumn = true;
} else {
LOG.debug("Ignoring implicit (absent) DiscriminatorColumn");
generateDiscriminatorColumn = false;
}
}
if (generateDiscriminatorColumn) {
final DiscriminatorType discriminatorType = discriminatorColumnAnnotation != null ? discriminatorColumnAnnotation.discriminatorType() : DiscriminatorType.STRING;
return Ejb3DiscriminatorColumn.buildDiscriminatorColumn(discriminatorType, discriminatorColumnAnnotation, null, context);
}
} else {
if (discriminatorColumnAnnotation != null) {
LOG.invalidDiscriminatorAnnotation(clazzToProcess.getName());
}
}
return null;
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class SessionFactoryImpl method resolveParameterBindType.
@Override
public Type resolveParameterBindType(Class clazz) {
String typename = clazz.getName();
Type type = getTypeResolver().heuristicType(typename);
boolean serializable = type != null && type instanceof SerializableType;
if (type == null || serializable) {
try {
getMetamodel().entityPersister(clazz.getName());
} catch (MappingException me) {
if (serializable) {
return type;
} else {
throw new HibernateException("Could not determine a type for class: " + typename);
}
}
return getTypeHelper().entity(clazz);
} else {
return type;
}
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class DefaultIdentifierGeneratorFactory method createIdentifierGenerator.
@Override
public IdentifierGenerator createIdentifierGenerator(String strategy, Type type, Properties config) {
try {
Class clazz = getIdentifierGeneratorClass(strategy);
IdentifierGenerator identifierGenerator = (IdentifierGenerator) clazz.newInstance();
if (identifierGenerator instanceof Configurable) {
((Configurable) identifierGenerator).configure(type, config, serviceRegistry);
}
return identifierGenerator;
} catch (Exception e) {
final String entityName = config.getProperty(IdentifierGenerator.ENTITY_NAME);
throw new MappingException(String.format("Could not instantiate id generator [entity-name=%s]", entityName), e);
}
}
Aggregations