use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class AttributeConverterTest method testBasicConverterApplication.
@Test
public void testBasicConverterApplication() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Tester.class).getMetadataBuilder().applyAttributeConverter(StringClobConverter.class, true).build();
PersistentClass tester = metadata.getEntityBinding(Tester.class.getName());
Property nameProp = tester.getProperty("name");
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
Type type = nameValue.getType();
assertNotNull(type);
assertTyping(BasicType.class, type);
if (!AttributeConverterTypeAdapter.class.isInstance(type)) {
fail("AttributeConverter not applied");
}
AbstractStandardBasicType basicType = assertTyping(AbstractStandardBasicType.class, type);
assertSame(StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor());
assertEquals(Types.CLOB, basicType.getSqlTypeDescriptor().getSqlType());
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class AttributeConverterTest method testNonAutoApplyHandling.
@Test
public void testNonAutoApplyHandling() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Tester.class).getMetadataBuilder().applyAttributeConverter(NotAutoAppliedConverter.class, false).build();
PersistentClass tester = metadata.getEntityBinding(Tester.class.getName());
Property nameProp = tester.getProperty("name");
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
Type type = nameValue.getType();
assertNotNull(type);
if (AttributeConverterTypeAdapter.class.isInstance(type)) {
fail("AttributeConverter with autoApply=false was auto applied");
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class MetadataImpl 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.mapping.Property 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.mapping.Property in project hibernate-orm by hibernate.
the class TypeSafeActivator method applyDDL.
private static void applyDDL(String prefix, PersistentClass persistentClass, Class<?> clazz, ValidatorFactory factory, Set<Class<?>> groups, boolean activateNotNull, Dialect dialect) {
final BeanDescriptor descriptor = factory.getValidator().getConstraintsForClass(clazz);
for (PropertyDescriptor propertyDesc : descriptor.getConstrainedProperties()) {
Property property = findPropertyByName(persistentClass, prefix + propertyDesc.getPropertyName());
boolean hasNotNull;
if (property != null) {
hasNotNull = applyConstraints(propertyDesc.getConstraintDescriptors(), property, propertyDesc, groups, activateNotNull, dialect);
if (property.isComposite() && propertyDesc.isCascaded()) {
Class<?> componentClass = ((Component) property.getValue()).getComponentClass();
/*
* we can apply not null if the upper component let's us activate not null
* and if the property is not null.
* Otherwise, all sub columns should be left nullable
*/
final boolean canSetNotNullOnColumns = activateNotNull && hasNotNull;
applyDDL(prefix + propertyDesc.getPropertyName() + ".", persistentClass, componentClass, factory, groups, canSetNotNullOnColumns, dialect);
}
//FIXME add collection of components
}
}
}
Aggregations