use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class NonReflectiveBinderTest method testMetaInheritance.
@Test
public void testMetaInheritance() {
PersistentClass cm = metadata.getEntityBinding("org.hibernate.test.legacy.Wicked");
Map m = cm.getMetaAttributes();
assertNotNull(m);
assertNotNull(cm.getMetaAttribute("global"));
assertNull(cm.getMetaAttribute("globalnoinherit"));
MetaAttribute metaAttribute = cm.getMetaAttribute("implements");
assertNotNull(metaAttribute);
assertEquals("implements", metaAttribute.getName());
assertTrue(metaAttribute.isMultiValued());
assertEquals(3, metaAttribute.getValues().size());
assertEquals("java.lang.Observer", metaAttribute.getValues().get(0));
assertEquals("java.lang.Observer", metaAttribute.getValues().get(1));
assertEquals("org.foo.BogusVisitor", metaAttribute.getValues().get(2));
/*Property property = cm.getIdentifierProperty();
property.getMetaAttribute(null);*/
Iterator propertyIterator = cm.getPropertyIterator();
while (propertyIterator.hasNext()) {
Property element = (Property) propertyIterator.next();
System.out.println(element);
Map ma = element.getMetaAttributes();
assertNotNull(ma);
assertNotNull(element.getMetaAttribute("global"));
MetaAttribute metaAttribute2 = element.getMetaAttribute("implements");
assertNotNull(metaAttribute2);
assertNull(element.getMetaAttribute("globalnoinherit"));
}
Property element = cm.getProperty("component");
Map ma = element.getMetaAttributes();
assertNotNull(ma);
assertNotNull(element.getMetaAttribute("global"));
assertNotNull(element.getMetaAttribute("componentonly"));
assertNotNull(element.getMetaAttribute("allcomponent"));
assertNull(element.getMetaAttribute("globalnoinherit"));
MetaAttribute compimplements = element.getMetaAttribute("implements");
assertNotNull(compimplements);
assertEquals(compimplements.getValue(), "AnotherInterface");
Property xp = ((Component) element.getValue()).getProperty("x");
MetaAttribute propximplements = xp.getMetaAttribute("implements");
assertNotNull(propximplements);
assertEquals(propximplements.getValue(), "AnotherInterface");
}
use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class NonReflectiveBinderTest method testComparator.
@Test
public void testComparator() {
PersistentClass cm = metadata.getEntityBinding("org.hibernate.test.legacy.Wicked");
Property property = cm.getProperty("sortedEmployee");
Collection col = (Collection) property.getValue();
assertEquals(col.getComparatorClassName(), "org.hibernate.test.legacy.NonExistingComparator");
}
use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class AnnotationBinder method mapAsIdClass.
private static boolean mapAsIdClass(Map<XClass, InheritanceState> inheritanceStatePerClass, InheritanceState inheritanceState, PersistentClass persistentClass, EntityBinder entityBinder, PropertyHolder propertyHolder, InheritanceState.ElementsToProcess elementsToProcess, Set<String> idPropertiesIfIdClass, MetadataBuildingContext context) {
/*
* We are looking for @IdClass
* In general we map the id class as identifier using the mapping metadata of the main entity's properties
* and we create an identifier mapper containing the id properties of the main entity
*
* In JPA 2, there is a shortcut if the id class is the Pk of the associated class pointed to by the id
* it ought to be treated as an embedded and not a real IdClass (at least in the Hibernate's internal way
*/
XClass classWithIdClass = inheritanceState.getClassWithIdClass(false);
if (classWithIdClass != null) {
IdClass idClass = classWithIdClass.getAnnotation(IdClass.class);
XClass compositeClass = context.getBuildingOptions().getReflectionManager().toXClass(idClass.value());
PropertyData inferredData = new PropertyPreloadedData(entityBinder.getPropertyAccessType(), "id", compositeClass);
PropertyData baseInferredData = new PropertyPreloadedData(entityBinder.getPropertyAccessType(), "id", classWithIdClass);
AccessType propertyAccessor = entityBinder.getPropertyAccessor(compositeClass);
//In JPA 2, there is a shortcut if the IdClass is the Pk of the associated class pointed to by the id
//it ought to be treated as an embedded and not a real IdClass (at least in the Hibernate's internal way
final boolean isFakeIdClass = isIdClassPkOfTheAssociatedEntity(elementsToProcess, compositeClass, inferredData, baseInferredData, propertyAccessor, inheritanceStatePerClass, context);
if (isFakeIdClass) {
return false;
}
boolean isComponent = true;
String generatorType = "assigned";
String generator = BinderHelper.ANNOTATION_STRING_DEFAULT;
boolean ignoreIdAnnotations = entityBinder.isIgnoreIdAnnotations();
entityBinder.setIgnoreIdAnnotations(true);
propertyHolder.setInIdClass(true);
bindIdClass(generatorType, generator, inferredData, baseInferredData, null, propertyHolder, isComponent, propertyAccessor, entityBinder, true, false, context, inheritanceStatePerClass);
propertyHolder.setInIdClass(null);
inferredData = new PropertyPreloadedData(propertyAccessor, PropertyPath.IDENTIFIER_MAPPER_PROPERTY, compositeClass);
Component mapper = fillComponent(propertyHolder, inferredData, baseInferredData, propertyAccessor, false, entityBinder, true, true, false, context, inheritanceStatePerClass);
entityBinder.setIgnoreIdAnnotations(ignoreIdAnnotations);
persistentClass.setIdentifierMapper(mapper);
//If id definition is on a mapped superclass, update the mapping
final org.hibernate.mapping.MappedSuperclass superclass = BinderHelper.getMappedSuperclassOrNull(classWithIdClass, inheritanceStatePerClass, context);
if (superclass != null) {
superclass.setDeclaredIdentifierMapper(mapper);
} else {
//we are for sure on the entity
persistentClass.setDeclaredIdentifierMapper(mapper);
}
Property property = new Property();
property.setName(PropertyPath.IDENTIFIER_MAPPER_PROPERTY);
property.setUpdateable(false);
property.setInsertable(false);
property.setValue(mapper);
property.setPropertyAccessorName("embedded");
persistentClass.addProperty(property);
entityBinder.setIgnoreIdAnnotations(true);
Iterator properties = mapper.getPropertyIterator();
while (properties.hasNext()) {
idPropertiesIfIdClass.add(((Property) properties.next()).getName());
}
return true;
} else {
return false;
}
}
use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class AnnotationBinder method bindAny.
private static void bindAny(String cascadeStrategy, Ejb3JoinColumn[] columns, boolean cascadeOnDelete, Nullability nullability, PropertyHolder propertyHolder, PropertyData inferredData, EntityBinder entityBinder, boolean isIdentifierMapper, MetadataBuildingContext buildingContext) {
org.hibernate.annotations.Any anyAnn = inferredData.getProperty().getAnnotation(org.hibernate.annotations.Any.class);
if (anyAnn == null) {
throw new AssertionFailure("Missing @Any annotation: " + BinderHelper.getPath(propertyHolder, inferredData));
}
Any value = BinderHelper.buildAnyValue(anyAnn.metaDef(), columns, anyAnn.metaColumn(), inferredData, cascadeOnDelete, nullability, propertyHolder, entityBinder, anyAnn.optional(), buildingContext);
PropertyBinder binder = new PropertyBinder();
binder.setName(inferredData.getPropertyName());
binder.setValue(value);
binder.setLazy(anyAnn.fetch() == FetchType.LAZY);
//binder.setCascade(cascadeStrategy);
if (isIdentifierMapper) {
binder.setInsertable(false);
binder.setUpdatable(false);
} else {
binder.setInsertable(columns[0].isInsertable());
binder.setUpdatable(columns[0].isUpdatable());
}
binder.setAccessType(inferredData.getDefaultAccess());
binder.setCascade(cascadeStrategy);
Property prop = binder.makeProperty();
//composite FK columns are in the same table so its OK
propertyHolder.addProperty(prop, columns, inferredData.getDeclaringClass());
}
use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class BinderHelper method shallowCopy.
/**
* create a property copy reusing the same value
*/
public static Property shallowCopy(Property property) {
Property clone = new Property();
clone.setCascade(property.getCascade());
clone.setInsertable(property.isInsertable());
clone.setLazy(property.isLazy());
clone.setName(property.getName());
clone.setNaturalIdentifier(property.isNaturalIdentifier());
clone.setOptimisticLocked(property.isOptimisticLocked());
clone.setOptional(property.isOptional());
clone.setPersistentClass(property.getPersistentClass());
clone.setPropertyAccessorName(property.getPropertyAccessorName());
clone.setSelectable(property.isSelectable());
clone.setUpdateable(property.isUpdateable());
clone.setValue(property.getValue());
return clone;
}
Aggregations