use of javax.persistence.AttributeOverride in project hibernate-orm by hibernate.
the class AbstractPropertyHolder method buildColumnOverride.
private static Map<String, Column[]> buildColumnOverride(XAnnotatedElement element, String path) {
Map<String, Column[]> columnOverride = new HashMap<String, Column[]>();
if (element != null) {
AttributeOverride singleOverride = element.getAnnotation(AttributeOverride.class);
AttributeOverrides multipleOverrides = element.getAnnotation(AttributeOverrides.class);
AttributeOverride[] overrides;
if (singleOverride != null) {
overrides = new AttributeOverride[] { singleOverride };
} else if (multipleOverrides != null) {
overrides = multipleOverrides.value();
} else {
overrides = null;
}
if (overrides != null) {
for (AttributeOverride depAttr : overrides) {
columnOverride.put(StringHelper.qualify(path, depAttr.name()), new Column[] { depAttr.column() });
}
}
}
return columnOverride;
}
use of javax.persistence.AttributeOverride in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method mergeAttributeOverrides.
/**
* @param mergeWithAnnotations Whether to use Java annotations for this
* element, if present and not disabled by the XMLContext defaults.
* In some contexts (such as an association mapping) merging with
* annotations is never allowed.
*/
private AttributeOverrides mergeAttributeOverrides(XMLContext.Default defaults, List<AttributeOverride> attributes, boolean mergeWithAnnotations) {
if (mergeWithAnnotations && defaults.canUseJavaAnnotations()) {
AttributeOverride annotation = getPhysicalAnnotation(AttributeOverride.class);
addAttributeOverrideIfNeeded(annotation, attributes);
AttributeOverrides annotations = getPhysicalAnnotation(AttributeOverrides.class);
if (annotations != null) {
for (AttributeOverride current : annotations.value()) {
addAttributeOverrideIfNeeded(current, attributes);
}
}
}
if (attributes.size() > 0) {
AnnotationDescriptor ad = new AnnotationDescriptor(AttributeOverrides.class);
ad.setValue("value", attributes.toArray(new AttributeOverride[attributes.size()]));
return AnnotationFactory.create(ad);
} else {
return null;
}
}
use of javax.persistence.AttributeOverride in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method buildAttributeOverrides.
private List<AttributeOverride> buildAttributeOverrides(List<Element> subelements, String nodeName) {
List<AttributeOverride> overrides = new ArrayList<AttributeOverride>();
if (subelements != null && subelements.size() > 0) {
for (Element current : subelements) {
if (!current.getName().equals(nodeName)) {
continue;
}
AnnotationDescriptor override = new AnnotationDescriptor(AttributeOverride.class);
copyStringAttribute(override, current, "name", true);
Element column = current.element("column");
override.setValue("column", getColumn(column, true, current));
overrides.add((AttributeOverride) AnnotationFactory.create(override));
}
}
return overrides;
}
use of javax.persistence.AttributeOverride in project hibernate-orm by hibernate.
the class Ejb3XmlElementCollectionTest method testSingleMapKeyAttributeOverride.
/**
* When there's a single map key attribute override, we still wrap it with
* an AttributeOverrides annotation.
*/
@Test
public void testSingleMapKeyAttributeOverride() throws Exception {
reader = getReader(Entity3.class, "field1", "element-collection.orm10.xml");
assertAnnotationPresent(ElementCollection.class);
assertAnnotationNotPresent(MapKey.class);
assertAnnotationNotPresent(MapKeyClass.class);
assertAnnotationNotPresent(MapKeyTemporal.class);
assertAnnotationNotPresent(MapKeyEnumerated.class);
assertAnnotationNotPresent(MapKeyColumn.class);
assertAnnotationNotPresent(MapKeyJoinColumns.class);
assertAnnotationNotPresent(MapKeyJoinColumn.class);
assertAnnotationNotPresent(AttributeOverride.class);
assertAnnotationPresent(AttributeOverrides.class);
AttributeOverrides overridesAnno = reader.getAnnotation(AttributeOverrides.class);
AttributeOverride[] overrides = overridesAnno.value();
assertEquals(1, overrides.length);
assertEquals("field1", overrides[0].name());
assertEquals("col1", overrides[0].column().name());
}
use of javax.persistence.AttributeOverride in project hibernate-orm by hibernate.
the class Ejb3XmlElementCollectionTest method testMixedAttributeOverrides.
/**
* Tests that map-key-attribute-override and attribute-override elements
* both end up in the AttributeOverrides annotation.
*/
@Test
public void testMixedAttributeOverrides() throws Exception {
reader = getReader(Entity3.class, "field1", "element-collection.orm23.xml");
assertAnnotationPresent(ElementCollection.class);
assertAnnotationNotPresent(AttributeOverride.class);
assertAnnotationPresent(AttributeOverrides.class);
AttributeOverrides overridesAnno = reader.getAnnotation(AttributeOverrides.class);
AttributeOverride[] overrides = overridesAnno.value();
assertEquals(2, overrides.length);
assertEquals("field1", overrides[0].name());
assertEquals("col1", overrides[0].column().name());
assertEquals("field2", overrides[1].name());
assertEquals("col2", overrides[1].column().name());
}
Aggregations