use of jakarta.persistence.MapKeyJoinColumns in project hibernate-orm by hibernate.
the class AnnotationBinder method mapKeyColumns.
private static JoinColumn[] mapKeyColumns(PropertyHolder propertyHolder, PropertyData inferredData, EntityBinder entityBinder, MetadataBuildingContext context, XProperty property, CollectionBinder collectionBinder, Comment comment) {
Column[] keyColumns = property.isAnnotationPresent(MapKeyColumn.class) ? new Column[] { new MapKeyColumnDelegator(property.getAnnotation(MapKeyColumn.class)) } : null;
AnnotatedColumn[] mapColumns = buildColumnsFromAnnotations(keyColumns, comment, Nullability.FORCED_NOT_NULL, propertyHolder, inferredData, "_KEY", entityBinder.getSecondaryTables(), context);
collectionBinder.setMapKeyColumns(mapColumns);
JoinColumn[] joinKeyColumns = null;
if (property.isAnnotationPresent(MapKeyJoinColumns.class)) {
final MapKeyJoinColumn[] mapKeyJoinColumns = property.getAnnotation(MapKeyJoinColumns.class).value();
joinKeyColumns = new JoinColumn[mapKeyJoinColumns.length];
int index = 0;
for (MapKeyJoinColumn joinColumn : mapKeyJoinColumns) {
joinKeyColumns[index] = new MapKeyJoinColumnDelegator(joinColumn);
index++;
}
if (property.isAnnotationPresent(MapKeyJoinColumn.class)) {
throw new AnnotationException("@MapKeyJoinColumn and @MapKeyJoinColumns used on the same property: " + BinderHelper.getPath(propertyHolder, inferredData));
}
} else if (property.isAnnotationPresent(MapKeyJoinColumn.class)) {
joinKeyColumns = new JoinColumn[] { new MapKeyJoinColumnDelegator(property.getAnnotation(MapKeyJoinColumn.class)) };
}
return joinKeyColumns;
}
use of jakarta.persistence.MapKeyJoinColumns in project hibernate-orm by hibernate.
the class Ejb3XmlElementCollectionTest method testSingleMapKeyJoinColumn.
/**
* When there's a single map key join column, we still wrap it with a
* MapKeyJoinColumns annotation.
*/
@Test
public void testSingleMapKeyJoinColumn() throws Exception {
reader = getReader(Entity3.class, "field1", "element-collection.orm14.xml");
assertAnnotationPresent(ElementCollection.class);
assertAnnotationNotPresent(MapKey.class);
assertAnnotationNotPresent(MapKeyClass.class);
assertAnnotationNotPresent(MapKeyTemporal.class);
assertAnnotationNotPresent(MapKeyEnumerated.class);
assertAnnotationNotPresent(MapKeyColumn.class);
assertAnnotationPresent(MapKeyJoinColumns.class);
assertAnnotationNotPresent(MapKeyJoinColumn.class);
MapKeyJoinColumns joinColumnsAnno = reader.getAnnotation(MapKeyJoinColumns.class);
MapKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
assertEquals(1, joinColumns.length);
assertEquals("col1", joinColumns[0].name());
}
use of jakarta.persistence.MapKeyJoinColumns in project hibernate-orm by hibernate.
the class Ejb3XmlOneToManyTest method testSingleMapKeyJoinColumn.
/**
* When there's a single map key join column, we still wrap it with a
* MapKeyJoinColumns annotation.
*/
@Test
public void testSingleMapKeyJoinColumn() throws Exception {
reader = getReader(Entity3.class, "field1", "one-to-many.orm14.xml");
assertAnnotationPresent(OneToMany.class);
assertAnnotationNotPresent(MapKey.class);
assertAnnotationNotPresent(MapKeyClass.class);
assertAnnotationNotPresent(MapKeyTemporal.class);
assertAnnotationNotPresent(MapKeyEnumerated.class);
assertAnnotationNotPresent(MapKeyColumn.class);
assertAnnotationPresent(MapKeyJoinColumns.class);
assertAnnotationNotPresent(MapKeyJoinColumn.class);
MapKeyJoinColumns joinColumnsAnno = reader.getAnnotation(MapKeyJoinColumns.class);
MapKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
assertEquals(1, joinColumns.length);
assertEquals("col1", joinColumns[0].name());
}
use of jakarta.persistence.MapKeyJoinColumns in project hibernate-orm by hibernate.
the class Ejb3XmlOneToManyTest method testMultipleMapKeyJoinColumns.
@Test
public void testMultipleMapKeyJoinColumns() throws Exception {
reader = getReader(Entity3.class, "field1", "one-to-many.orm15.xml");
assertAnnotationPresent(OneToMany.class);
assertAnnotationNotPresent(MapKey.class);
assertAnnotationNotPresent(MapKeyClass.class);
assertAnnotationNotPresent(MapKeyTemporal.class);
assertAnnotationNotPresent(MapKeyEnumerated.class);
assertAnnotationNotPresent(MapKeyColumn.class);
assertAnnotationPresent(MapKeyJoinColumns.class);
assertAnnotationNotPresent(MapKeyJoinColumn.class);
MapKeyJoinColumns joinColumnsAnno = reader.getAnnotation(MapKeyJoinColumns.class);
MapKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
assertEquals(2, joinColumns.length);
assertEquals("", joinColumns[0].name());
assertEquals("", joinColumns[0].referencedColumnName());
assertFalse(joinColumns[0].unique());
assertFalse(joinColumns[0].nullable());
assertTrue(joinColumns[0].insertable());
assertTrue(joinColumns[0].updatable());
assertEquals("", joinColumns[0].columnDefinition());
assertEquals("", joinColumns[0].table());
assertEquals("col1", joinColumns[1].name());
assertEquals("col2", joinColumns[1].referencedColumnName());
assertTrue(joinColumns[1].unique());
assertTrue(joinColumns[1].nullable());
assertFalse(joinColumns[1].insertable());
assertFalse(joinColumns[1].updatable());
assertEquals("int", joinColumns[1].columnDefinition());
assertEquals("table1", joinColumns[1].table());
}
use of jakarta.persistence.MapKeyJoinColumns in project hibernate-orm by hibernate.
the class Ejb3XmlElementCollectionTest method testMultipleMapKeyJoinColumns.
@Test
public void testMultipleMapKeyJoinColumns() throws Exception {
reader = getReader(Entity3.class, "field1", "element-collection.orm15.xml");
assertAnnotationPresent(ElementCollection.class);
assertAnnotationNotPresent(MapKey.class);
assertAnnotationNotPresent(MapKeyClass.class);
assertAnnotationNotPresent(MapKeyTemporal.class);
assertAnnotationNotPresent(MapKeyEnumerated.class);
assertAnnotationNotPresent(MapKeyColumn.class);
assertAnnotationPresent(MapKeyJoinColumns.class);
assertAnnotationNotPresent(MapKeyJoinColumn.class);
MapKeyJoinColumns joinColumnsAnno = reader.getAnnotation(MapKeyJoinColumns.class);
MapKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
assertEquals(2, joinColumns.length);
assertEquals("", joinColumns[0].name());
assertEquals("", joinColumns[0].referencedColumnName());
assertFalse(joinColumns[0].unique());
assertFalse(joinColumns[0].nullable());
assertTrue(joinColumns[0].insertable());
assertTrue(joinColumns[0].updatable());
assertEquals("", joinColumns[0].columnDefinition());
assertEquals("", joinColumns[0].table());
assertEquals("col1", joinColumns[1].name());
assertEquals("col2", joinColumns[1].referencedColumnName());
assertTrue(joinColumns[1].unique());
assertTrue(joinColumns[1].nullable());
assertFalse(joinColumns[1].insertable());
assertFalse(joinColumns[1].updatable());
assertEquals("int", joinColumns[1].columnDefinition());
assertEquals("table1", joinColumns[1].table());
}
Aggregations