use of jakarta.persistence.JoinColumns in project hibernate-orm by hibernate.
the class ColumnsBuilder method extractMetadata.
public ColumnsBuilder extractMetadata() {
columns = null;
joinColumns = buildExplicitJoinColumns(property, inferredData);
Comment comment = property.getAnnotation(Comment.class);
if (property.isAnnotationPresent(Column.class)) {
columns = buildColumnFromAnnotation(property.getAnnotation(Column.class), comment, nullability, propertyHolder, inferredData, entityBinder.getSecondaryTables(), buildingContext);
} else if (property.isAnnotationPresent(Formula.class)) {
columns = buildFormulaFromAnnotation(getOverridableAnnotation(property, Formula.class, buildingContext), comment, nullability, propertyHolder, inferredData, entityBinder.getSecondaryTables(), buildingContext);
} else if (property.isAnnotationPresent(Columns.class)) {
columns = buildColumnsFromAnnotations(property.getAnnotation(Columns.class).columns(), comment, nullability, propertyHolder, inferredData, entityBinder.getSecondaryTables(), buildingContext);
}
// set default values if needed
if (joinColumns == null && (property.isAnnotationPresent(ManyToOne.class) || property.isAnnotationPresent(OneToOne.class))) {
joinColumns = buildDefaultJoinColumnsForXToOne(property, inferredData);
} else if (joinColumns == null && (property.isAnnotationPresent(OneToMany.class) || property.isAnnotationPresent(ElementCollection.class))) {
OneToMany oneToMany = property.getAnnotation(OneToMany.class);
joinColumns = AnnotatedJoinColumn.buildJoinColumns(null, comment, oneToMany != null ? oneToMany.mappedBy() : "", entityBinder.getSecondaryTables(), propertyHolder, inferredData.getPropertyName(), buildingContext);
} else if (joinColumns == null && property.isAnnotationPresent(org.hibernate.annotations.Any.class)) {
throw new AnnotationException("@Any requires an explicit @JoinColumn(s): " + BinderHelper.getPath(propertyHolder, inferredData));
}
if (columns == null && !property.isAnnotationPresent(ManyToMany.class)) {
// useful for collection of embedded elements
columns = buildColumnFromNoAnnotation(comment, nullability, propertyHolder, inferredData, entityBinder.getSecondaryTables(), buildingContext);
}
if (nullability == Nullability.FORCED_NOT_NULL) {
// force columns to not null
for (AnnotatedColumn col : columns) {
col.forceNotNull();
}
}
return this;
}
use of jakarta.persistence.JoinColumns in project hibernate-orm by hibernate.
the class Ejb3XmlManyToOneTest method testMultipleJoinColumns.
@Test
public void testMultipleJoinColumns() throws Exception {
reader = getReader(Entity1.class, "field1", "many-to-one.orm3.xml");
assertAnnotationPresent(ManyToOne.class);
assertAnnotationNotPresent(JoinColumn.class);
assertAnnotationPresent(JoinColumns.class);
assertAnnotationNotPresent(JoinTable.class);
JoinColumns joinColumnsAnno = reader.getAnnotation(JoinColumns.class);
JoinColumn[] joinColumns = joinColumnsAnno.value();
assertEquals(2, joinColumns.length);
assertEquals("", joinColumns[0].name());
assertEquals("", joinColumns[0].referencedColumnName());
assertEquals("", joinColumns[0].table());
assertEquals("", joinColumns[0].columnDefinition());
assertTrue(joinColumns[0].insertable());
assertTrue(joinColumns[0].updatable());
assertTrue(joinColumns[0].nullable());
assertFalse(joinColumns[0].unique());
assertEquals("col1", joinColumns[1].name());
assertEquals("col2", joinColumns[1].referencedColumnName());
assertEquals("table1", joinColumns[1].table());
assertEquals("int", joinColumns[1].columnDefinition());
assertFalse(joinColumns[1].insertable());
assertFalse(joinColumns[1].updatable());
assertFalse(joinColumns[1].nullable());
assertTrue(joinColumns[1].unique());
}
use of jakarta.persistence.JoinColumns in project hibernate-orm by hibernate.
the class Ejb3XmlManyToOneTest method testSingleJoinColumn.
/**
* When there's a single join column, we still wrap it with a JoinColumns
* annotation.
*/
@Test
public void testSingleJoinColumn() throws Exception {
reader = getReader(Entity1.class, "field1", "many-to-one.orm2.xml");
assertAnnotationPresent(ManyToOne.class);
assertAnnotationNotPresent(JoinColumn.class);
assertAnnotationPresent(JoinColumns.class);
assertAnnotationNotPresent(JoinTable.class);
JoinColumns joinColumnsAnno = reader.getAnnotation(JoinColumns.class);
JoinColumn[] joinColumns = joinColumnsAnno.value();
assertEquals(1, joinColumns.length);
assertEquals("col1", joinColumns[0].name());
assertEquals("col2", joinColumns[0].referencedColumnName());
assertEquals("table1", joinColumns[0].table());
}
use of jakarta.persistence.JoinColumns in project hibernate-orm by hibernate.
the class Ejb3XmlOneToOneTest method testSingleJoinColumn.
/**
* When there's a single join column, we still wrap it with a JoinColumns
* annotation.
*/
@Test
public void testSingleJoinColumn() throws Exception {
reader = getReader(Entity1.class, "field1", "one-to-one.orm4.xml");
assertAnnotationPresent(OneToOne.class);
assertAnnotationNotPresent(PrimaryKeyJoinColumn.class);
assertAnnotationNotPresent(PrimaryKeyJoinColumns.class);
assertAnnotationPresent(JoinColumns.class);
assertAnnotationNotPresent(JoinColumn.class);
assertAnnotationNotPresent(JoinTable.class);
JoinColumns joinColumnsAnno = reader.getAnnotation(JoinColumns.class);
JoinColumn[] joinColumns = joinColumnsAnno.value();
assertEquals(1, joinColumns.length);
assertEquals("col1", joinColumns[0].name());
assertEquals("col2", joinColumns[0].referencedColumnName());
assertEquals("table1", joinColumns[0].table());
}
use of jakarta.persistence.JoinColumns in project hibernate-orm by hibernate.
the class Ejb3XmlOneToManyTest method testSingleJoinColumn.
/**
* When there's a single join column, we still wrap it with a JoinColumns
* annotation.
*/
@Test
public void testSingleJoinColumn() throws Exception {
reader = getReader(Entity2.class, "field1", "one-to-many.orm18.xml");
assertAnnotationPresent(OneToMany.class);
assertAnnotationNotPresent(JoinColumn.class);
assertAnnotationPresent(JoinColumns.class);
assertAnnotationNotPresent(JoinTable.class);
JoinColumns joinColumnsAnno = reader.getAnnotation(JoinColumns.class);
JoinColumn[] joinColumns = joinColumnsAnno.value();
assertEquals(1, joinColumns.length);
assertEquals("col1", joinColumns[0].name());
assertEquals("col2", joinColumns[0].referencedColumnName());
assertEquals("table1", joinColumns[0].table());
}
Aggregations