use of org.hibernate.metamodel.UnsupportedMappingException in project hibernate-orm by hibernate.
the class AttributeFactory method determineAttributeMetadata.
private static <X, Y> AttributeMetadata<X, Y> determineAttributeMetadata(AttributeContext<X> attributeContext, MemberResolver memberResolver, MetadataContext context) {
final Property propertyMapping = attributeContext.getPropertyMapping();
final String propertyName = propertyMapping.getName();
LOG.tracef("Starting attribute metadata determination [%s]", propertyName);
final Member member = memberResolver.resolveMember(attributeContext, context);
LOG.tracef(" Determined member [%s]", member);
final Value value = propertyMapping.getValue();
final org.hibernate.type.Type type = value.getType();
LOG.tracef(" Determined type [name=%s, class=%s]", type.getName(), type.getClass().getName());
if (type.isAnyType()) {
return new SingularAttributeMetadataImpl<>(propertyMapping, attributeContext.getOwnerType(), member, AttributeClassification.ANY, context);
} else if (type.isAssociationType()) {
// collection or entity
if (type.isEntityType()) {
// entity
return new SingularAttributeMetadataImpl<>(propertyMapping, attributeContext.getOwnerType(), member, determineSingularAssociationClassification(member), context);
}
// collection
if (value instanceof Collection) {
final Collection collValue = (Collection) value;
final Value elementValue = collValue.getElement();
final org.hibernate.type.Type elementType = elementValue.getType();
final boolean isManyToMany = isManyToMany(member);
// First, determine the type of the elements and use that to help determine the
// collection type
final AttributeClassification elementClassification;
final AttributeClassification attributeClassification;
if (elementType.isAnyType()) {
attributeClassification = AttributeClassification.ELEMENT_COLLECTION;
elementClassification = AttributeClassification.ANY;
} else if (elementValue instanceof Component) {
elementClassification = AttributeClassification.EMBEDDED;
attributeClassification = AttributeClassification.ELEMENT_COLLECTION;
} else if (elementType.isAssociationType()) {
elementClassification = isManyToMany ? AttributeClassification.MANY_TO_MANY : AttributeClassification.ONE_TO_MANY;
attributeClassification = elementClassification;
} else {
elementClassification = AttributeClassification.BASIC;
attributeClassification = AttributeClassification.ELEMENT_COLLECTION;
}
final AttributeClassification indexClassification;
// Finally, we determine the type of the map key (if needed)
if (value instanceof Map) {
final Value keyValue = ((Map) value).getIndex();
final org.hibernate.type.Type keyType = keyValue.getType();
if (keyType.isAnyType()) {
indexClassification = AttributeClassification.ANY;
} else if (keyValue instanceof Component) {
indexClassification = AttributeClassification.EMBEDDED;
} else if (keyType.isAssociationType()) {
indexClassification = AttributeClassification.MANY_TO_ONE;
} else {
indexClassification = AttributeClassification.BASIC;
}
} else if (value instanceof List) {
indexClassification = AttributeClassification.BASIC;
} else {
indexClassification = null;
}
return new PluralAttributeMetadataImpl<>(propertyMapping, attributeContext.getOwnerType(), member, attributeClassification, elementClassification, indexClassification, context);
} else if (value instanceof OneToMany) {
// element value within a o.h.mapping.Collection (see logic branch above)
throw new IllegalArgumentException("HUH???");
// final boolean isManyToMany = isManyToMany( member );
// //one to many with FK => entity
// return new PluralAttributeMetadataImpl(
// attributeContext.getPropertyMapping(),
// attributeContext.getOwnerType(),
// member,
// isManyToMany
// ? Attribute.PersistentAttributeType.MANY_TO_MANY
// : Attribute.PersistentAttributeType.ONE_TO_MANY
// value,
// AttributeContext.TypeStatus.ENTITY,
// Attribute.PersistentAttributeType.ONE_TO_MANY,
// null, null, null
// );
}
} else if (propertyMapping.isComposite()) {
// component
return new SingularAttributeMetadataImpl<>(propertyMapping, attributeContext.getOwnerType(), member, AttributeClassification.EMBEDDED, context);
} else {
// basic type
return new SingularAttributeMetadataImpl<>(propertyMapping, attributeContext.getOwnerType(), member, AttributeClassification.BASIC, context);
}
throw new UnsupportedMappingException("oops, we are missing something: " + propertyMapping);
}
use of org.hibernate.metamodel.UnsupportedMappingException in project hibernate-orm by hibernate.
the class CompoundNaturalIdMapping method normalizeInput.
@Override
@SuppressWarnings("rawtypes")
public Object[] normalizeInput(Object incoming, SharedSessionContractImplementor session) {
if (incoming instanceof Object[]) {
return (Object[]) incoming;
}
if (incoming instanceof Map) {
final Map valueMap = (Map) incoming;
final List<SingularAttributeMapping> attributes = getNaturalIdAttributes();
final Object[] values = new Object[attributes.size()];
for (int i = 0; i < attributes.size(); i++) {
values[i] = valueMap.get(attributes.get(i).getAttributeName());
}
return values;
}
throw new UnsupportedMappingException("Do not know how to normalize compound natural-id value : " + incoming);
}
use of org.hibernate.metamodel.UnsupportedMappingException in project hibernate-orm by hibernate.
the class GeneratedValuesProcessor method processGeneratedValues.
public void processGeneratedValues(Object entity, Object id, Object[] state, SharedSessionContractImplementor session) {
if (selectStatement == null) {
return;
}
final JdbcServices jdbcServices = sessionFactory.getJdbcServices();
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
final SqlAstTranslatorFactory sqlAstTranslatorFactory = jdbcEnvironment.getSqlAstTranslatorFactory();
final JdbcParameterBindings jdbcParamBindings = new JdbcParameterBindingsImpl(jdbcParameters.size());
int offset = jdbcParamBindings.registerParametersForEachJdbcValue(id, Clause.WHERE, entityDescriptor.getIdentifierMapping(), jdbcParameters, session);
assert offset == jdbcParameters.size();
final JdbcSelect jdbcSelect = sqlAstTranslatorFactory.buildSelectTranslator(sessionFactory, selectStatement).translate(jdbcParamBindings, QueryOptions.NONE);
final List<Object[]> results = session.getFactory().getJdbcServices().getJdbcSelectExecutor().list(jdbcSelect, jdbcParamBindings, new ExecutionContext() {
@Override
public SharedSessionContractImplementor getSession() {
return session;
}
@Override
public QueryOptions getQueryOptions() {
return QueryOptions.NONE;
}
@Override
public String getQueryIdentifier(String sql) {
return sql;
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return QueryParameterBindings.NO_PARAM_BINDINGS;
}
@Override
public Callback getCallback() {
throw new UnsupportedMappingException("Follow-on locking not supported yet");
}
}, (row) -> row, ListResultsConsumer.UniqueSemantic.FILTER);
assert results.size() == 1;
final Object[] dbSelectionResults = results.get(0);
for (int i = 0; i < valueDescriptors.size(); i++) {
final GeneratedValueDescriptor descriptor = valueDescriptors.get(i);
final Object generatedValue = descriptor.resolver.resolveGeneratedValue(dbSelectionResults, entity, session);
state[descriptor.attribute.getStateArrayPosition()] = generatedValue;
descriptor.attribute.getAttributeMetadataAccess().resolveAttributeMetadata(entityDescriptor).getPropertyAccess().getSetter().set(entity, generatedValue);
}
}
Aggregations