use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class PersistentClass method getRecursiveProperty.
private Property getRecursiveProperty(String propertyPath, Iterator iter) throws MappingException {
Property property = null;
StringTokenizer st = new StringTokenizer(propertyPath, ".", false);
try {
while (st.hasMoreElements()) {
final String element = (String) st.nextElement();
if (property == null) {
Property identifierProperty = getIdentifierProperty();
if (identifierProperty != null && identifierProperty.getName().equals(element)) {
// we have a mapped identifier property and the root of
// the incoming property path matched that identifier
// property
property = identifierProperty;
} else if (identifierProperty == null && getIdentifierMapper() != null) {
// we have an embedded composite identifier
try {
identifierProperty = getProperty(element, getIdentifierMapper().getPropertyIterator());
if (identifierProperty != null) {
// the root of the incoming property path matched one
// of the embedded composite identifier properties
property = identifierProperty;
}
} catch (MappingException ignore) {
// ignore it...
}
}
if (property == null) {
property = getProperty(element, iter);
}
} else {
//flat recursive algorithm
property = ((Component) property.getValue()).getProperty(element);
}
}
} catch (MappingException e) {
throw new MappingException("property [" + propertyPath + "] not found on entity [" + getEntityName() + "]");
}
return property;
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class AbstractEntityPersister method collectAttributeDefinitions.
private void collectAttributeDefinitions(Map<String, AttributeDefinition> attributeDefinitionsByName, EntityMetamodel metamodel) {
for (int i = 0; i < metamodel.getPropertySpan(); i++) {
final AttributeDefinition attributeDefinition = metamodel.getProperties()[i];
// Don't replace an attribute definition if it is already in attributeDefinitionsByName
// because the new value will be from a subclass.
final AttributeDefinition oldAttributeDefinition = attributeDefinitionsByName.get(attributeDefinition.getName());
if (oldAttributeDefinition != null) {
if (LOG.isTraceEnabled()) {
LOG.tracef("Ignoring subclass attribute definition [%s.%s] because it is defined in a superclass ", entityMetamodel.getName(), attributeDefinition.getName());
}
} else {
attributeDefinitionsByName.put(attributeDefinition.getName(), attributeDefinition);
}
}
// see if there are any subclass persisters...
final Set<String> subClassEntityNames = metamodel.getSubclassEntityNames();
if (subClassEntityNames == null) {
return;
}
// see if we can find the persisters...
for (String subClassEntityName : subClassEntityNames) {
if (metamodel.getName().equals(subClassEntityName)) {
// skip it
continue;
}
try {
final EntityPersister subClassEntityPersister = factory.getEntityPersister(subClassEntityName);
collectAttributeDefinitions(attributeDefinitionsByName, subClassEntityPersister.getEntityMetamodel());
} catch (MappingException e) {
throw new IllegalStateException(String.format("Could not locate subclass EntityPersister [%s] while processing EntityPersister [%s]", subClassEntityName, metamodel.getName()), e);
}
}
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class AbstractPropertyMapping method initComponentPropertyPaths.
protected void initComponentPropertyPaths(final String path, final CompositeType type, final String[] columns, final String[] columnReaders, final String[] columnReaderTemplates, String[] formulaTemplates, final Mapping factory) throws MappingException {
Type[] types = type.getSubtypes();
String[] properties = type.getPropertyNames();
int begin = 0;
for (int i = 0; i < properties.length; i++) {
String subpath = extendPath(path, properties[i]);
try {
int length = types[i].getColumnSpan(factory);
String[] columnSlice = ArrayHelper.slice(columns, begin, length);
String[] columnReaderSlice = ArrayHelper.slice(columnReaders, begin, length);
String[] columnReaderTemplateSlice = ArrayHelper.slice(columnReaderTemplates, begin, length);
String[] formulaSlice = formulaTemplates == null ? null : ArrayHelper.slice(formulaTemplates, begin, length);
initPropertyPaths(subpath, types[i], columnSlice, columnReaderSlice, columnReaderTemplateSlice, formulaSlice, factory);
begin += length;
} catch (Exception e) {
throw new MappingException("bug in initComponentPropertyPaths", e);
}
}
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class NamedQueryRepository method checkNamedQueries.
public Map<String, HibernateException> checkNamedQueries(QueryPlanCache queryPlanCache) {
Map<String, HibernateException> errors = new HashMap<String, HibernateException>();
// Check named HQL queries
log.debugf("Checking %s named HQL queries", namedQueryDefinitionMap.size());
for (NamedQueryDefinition namedQueryDefinition : namedQueryDefinitionMap.values()) {
// this will throw an error if there's something wrong.
try {
log.debugf("Checking named query: %s", namedQueryDefinition.getName());
//TODO: BUG! this currently fails for named queries for non-POJO entities
queryPlanCache.getHQLQueryPlan(namedQueryDefinition.getQueryString(), false, Collections.EMPTY_MAP);
} catch (HibernateException e) {
errors.put(namedQueryDefinition.getName(), e);
}
}
// Check native-sql queries
log.debugf("Checking %s named SQL queries", namedSqlQueryDefinitionMap.size());
for (NamedSQLQueryDefinition namedSQLQueryDefinition : namedSqlQueryDefinitionMap.values()) {
// this will throw an error if there's something wrong.
try {
log.debugf("Checking named SQL query: %s", namedSQLQueryDefinition.getName());
// TODO : would be really nice to cache the spec on the query-def so as to not have to re-calc the hash;
// currently not doable though because of the resultset-ref stuff...
NativeSQLQuerySpecification spec;
if (namedSQLQueryDefinition.getResultSetRef() != null) {
ResultSetMappingDefinition definition = getResultSetMappingDefinition(namedSQLQueryDefinition.getResultSetRef());
if (definition == null) {
throw new MappingException("Unable to find resultset-ref definition: " + namedSQLQueryDefinition.getResultSetRef());
}
spec = new NativeSQLQuerySpecification(namedSQLQueryDefinition.getQueryString(), definition.getQueryReturns(), namedSQLQueryDefinition.getQuerySpaces());
} else {
spec = new NativeSQLQuerySpecification(namedSQLQueryDefinition.getQueryString(), namedSQLQueryDefinition.getQueryReturns(), namedSQLQueryDefinition.getQuerySpaces());
}
queryPlanCache.getNativeSQLQueryPlan(spec);
} catch (HibernateException e) {
errors.put(namedSQLQueryDefinition.getName(), e);
}
}
return errors;
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class CollectionBinderTest method testAssociatedClassException.
@Test
@TestForIssue(jiraKey = "HHH-10106")
public void testAssociatedClassException() throws SQLException {
final Collection collection = mock(Collection.class);
final Map persistentClasses = mock(Map.class);
final XClass collectionType = mock(XClass.class);
final MetadataBuildingContext buildingContext = mock(MetadataBuildingContext.class);
final InFlightMetadataCollector inFly = mock(InFlightMetadataCollector.class);
final PersistentClass persistentClass = mock(PersistentClass.class);
final Table table = mock(Table.class);
when(buildingContext.getMetadataCollector()).thenReturn(inFly);
when(persistentClasses.get(null)).thenReturn(null);
when(collection.getOwner()).thenReturn(persistentClass);
when(collectionType.getName()).thenReturn("List");
when(persistentClass.getTable()).thenReturn(table);
when(table.getName()).thenReturn("Hibernate");
CollectionBinder collectionBinder = new CollectionBinder(false) {
@Override
protected Collection createCollection(PersistentClass persistentClass) {
return null;
}
{
final PropertyHolder propertyHolder = Mockito.mock(PropertyHolder.class);
when(propertyHolder.getClassName()).thenReturn(CollectionBinderTest.class.getSimpleName());
this.propertyName = "abc";
this.propertyHolder = propertyHolder;
}
};
String expectMessage = "Association [abc] for entity [CollectionBinderTest] references unmapped class [List]";
try {
collectionBinder.bindOneToManySecondPass(collection, persistentClasses, null, collectionType, false, false, buildingContext, null);
} catch (MappingException e) {
assertEquals(expectMessage, e.getMessage());
}
}
Aggregations