use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class InFlightMetadataCollectorImpl method getReferencedPropertyType.
@Override
public org.hibernate.type.Type getReferencedPropertyType(String entityName, String propertyName) throws MappingException {
final PersistentClass pc = entityBindingMap.get(entityName);
if (pc == null) {
throw new MappingException("persistent class not known: " + entityName);
}
Property prop = pc.getReferencedProperty(propertyName);
if (prop == null) {
throw new MappingException("property not known: " + entityName + '.' + propertyName);
}
return prop.getType();
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class TypeSafeActivator method findPropertyByName.
/**
* Locate the property by path in a recursive way, including IdentifierProperty in the loop if propertyName is
* {@code null}. If propertyName is {@code null} or empty, the IdentifierProperty is returned
*/
private static Property findPropertyByName(PersistentClass associatedClass, String propertyName) {
Property property = null;
Property idProperty = associatedClass.getIdentifierProperty();
String idName = idProperty != null ? idProperty.getName() : null;
try {
if (propertyName == null || propertyName.length() == 0 || propertyName.equals(idName)) {
//default to id
property = idProperty;
} else {
if (propertyName.indexOf(idName + ".") == 0) {
property = idProperty;
propertyName = propertyName.substring(idName.length() + 1);
}
StringTokenizer st = new StringTokenizer(propertyName, ".", false);
while (st.hasMoreElements()) {
String element = (String) st.nextElement();
if (property == null) {
property = associatedClass.getProperty(element);
} else {
if (!property.isComposite()) {
return null;
}
property = ((Component) property.getValue()).getProperty(element);
}
}
}
} catch (MappingException e) {
try {
//if we do not find it try to check the identifier mapper
if (associatedClass.getIdentifierMapper() == null) {
return null;
}
StringTokenizer st = new StringTokenizer(propertyName, ".", false);
while (st.hasMoreElements()) {
String element = (String) st.nextElement();
if (property == null) {
property = associatedClass.getIdentifierMapper().getProperty(element);
} else {
if (!property.isComposite()) {
return null;
}
property = ((Component) property.getValue()).getProperty(element);
}
}
} catch (MappingException ee) {
return null;
}
}
return property;
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class QueryTranslatorImpl method addFromAssociation.
/**
* Used for collection filters
*/
private void addFromAssociation(final String elementName, final String collectionRole) throws QueryException {
//q.addCollection(collectionName, collectionRole);
QueryableCollection persister = getCollectionPersister(collectionRole);
Type collectionElementType = persister.getElementType();
if (!collectionElementType.isEntityType()) {
throw new QueryException("collection of values in filter: " + elementName);
}
String[] keyColumnNames = persister.getKeyColumnNames();
//if (keyColumnNames.length!=1) throw new QueryException("composite-key collection in filter: " + collectionRole);
String collectionName;
JoinSequence join = new JoinSequence(getFactory());
collectionName = persister.isOneToMany() ? elementName : createNameForCollection(collectionRole);
join.setRoot(persister, collectionName);
if (!persister.isOneToMany()) {
//many-to-many
addCollection(collectionName, collectionRole);
try {
join.addJoin((AssociationType) persister.getElementType(), elementName, JoinType.INNER_JOIN, persister.getElementColumnNames(collectionName));
} catch (MappingException me) {
throw new QueryException(me);
}
}
join.addCondition(collectionName, keyColumnNames, " = ?");
//if ( persister.hasWhere() ) join.addCondition( persister.getSQLWhereString(collectionName) );
EntityType elemType = (EntityType) collectionElementType;
addFrom(elementName, elemType.getAssociatedEntityName(), join);
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class LiteralProcessor method setConstantValue.
private void setConstantValue(DotNode node, String text, Object value) {
if (LOG.isDebugEnabled()) {
LOG.debugf("setConstantValue() %s -> %s %s", text, value, value.getClass().getName());
}
// Chop off the rest of the tree.
node.setFirstChild(null);
if (value instanceof String) {
node.setType(SqlTokenTypes.QUOTED_STRING);
} else if (value instanceof Character) {
node.setType(SqlTokenTypes.QUOTED_STRING);
} else if (value instanceof Byte) {
node.setType(SqlTokenTypes.NUM_INT);
} else if (value instanceof Short) {
node.setType(SqlTokenTypes.NUM_INT);
} else if (value instanceof Integer) {
node.setType(SqlTokenTypes.NUM_INT);
} else if (value instanceof Long) {
node.setType(SqlTokenTypes.NUM_LONG);
} else if (value instanceof Double) {
node.setType(SqlTokenTypes.NUM_DOUBLE);
} else if (value instanceof Float) {
node.setType(SqlTokenTypes.NUM_FLOAT);
} else {
node.setType(SqlTokenTypes.CONSTANT);
}
Type type;
try {
type = walker.getSessionFactoryHelper().getFactory().getTypeResolver().heuristicType(value.getClass().getName());
} catch (MappingException me) {
throw new QueryException(me);
}
if (type == null) {
throw new QueryException(QueryTranslator.ERROR_CANNOT_DETERMINE_TYPE + node.getText());
}
try {
LiteralType literalType = (LiteralType) type;
Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
//noinspection unchecked
node.setText(literalType.objectToSQLString(value, dialect));
} catch (Exception e) {
throw new QueryException(QueryTranslator.ERROR_CANNOT_FORMAT_LITERAL + node.getText(), e);
}
node.setDataType(type);
node.setResolvedConstant(text);
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class SimpleValue method createParameterImpl.
private void createParameterImpl() {
try {
String[] columnsNames = new String[columns.size()];
for (int i = 0; i < columns.size(); i++) {
Selectable column = columns.get(i);
if (column instanceof Column) {
columnsNames[i] = ((Column) column).getName();
}
}
final XProperty xProperty = (XProperty) typeParameters.get(DynamicParameterizedType.XPROPERTY);
// todo : not sure this works for handling @MapKeyEnumerated
final Annotation[] annotations = xProperty == null ? null : xProperty.getAnnotations();
final ClassLoaderService classLoaderService = getMetadata().getMetadataBuildingOptions().getServiceRegistry().getService(ClassLoaderService.class);
typeParameters.put(DynamicParameterizedType.PARAMETER_TYPE, new ParameterTypeImpl(classLoaderService.classForName(typeParameters.getProperty(DynamicParameterizedType.RETURNED_CLASS)), annotations, table.getCatalog(), table.getSchema(), table.getName(), Boolean.valueOf(typeParameters.getProperty(DynamicParameterizedType.IS_PRIMARY_KEY)), columnsNames));
} catch (ClassLoadingException e) {
throw new MappingException("Could not create DynamicParameterizedType for type: " + typeName, e);
}
}
Aggregations