use of org.hibernate.query.BindableType in project hibernate-orm by hibernate.
the class AbstractCommonQueryContract method setProperties.
@Override
public CommonQueryContract setProperties(Object bean) {
final Class<?> clazz = bean.getClass();
for (String paramName : getParameterMetadata().getNamedParameterNames()) {
try {
final PropertyAccess propertyAccess = BuiltInPropertyAccessStrategies.BASIC.getStrategy().buildPropertyAccess(clazz, paramName, true);
final Getter getter = propertyAccess.getGetter();
final Class<?> retType = getter.getReturnTypeClass();
final Object object = getter.get(bean);
if (Collection.class.isAssignableFrom(retType)) {
setParameterList(paramName, (Collection<?>) object);
} else if (retType.isArray()) {
setParameterList(paramName, (Object[]) object);
} else {
BindableType<Object> type = determineType(paramName, retType);
setParameter(paramName, object, type);
}
} catch (PropertyNotFoundException pnfe) {
// ignore
}
}
return this;
}
use of org.hibernate.query.BindableType in project hibernate-orm by hibernate.
the class ConverterTest method testJPQLUpperAttributeValueBindParameterType.
@Test
public void testJPQLUpperAttributeValueBindParameterType(EntityManagerFactoryScope scope) {
scope.inTransaction(entityManager -> {
// tag::basic-attribute-converter-query-parameter-converter-object-example[]
SessionFactoryImplementor sessionFactory = entityManager.getEntityManagerFactory().unwrap(SessionFactoryImplementor.class);
final MappingMetamodelImplementor mappingMetamodel = sessionFactory.getRuntimeMetamodels().getMappingMetamodel();
Type captionType = mappingMetamodel.getEntityDescriptor(Photo.class).getPropertyType("caption");
Photo photo = (Photo) entityManager.createQuery("select p " + "from Photo p " + "where upper(caption) = upper(:caption) ", Photo.class).unwrap(Query.class).setParameter("caption", new Caption("Nicolae Grigorescu"), (BindableType) captionType).getSingleResult();
// end::basic-attribute-converter-query-parameter-converter-object-example[]
assertEquals("Dorobantul", photo.getName());
});
}
Aggregations