use of jakarta.persistence.PrimaryKeyJoinColumn in project hibernate-orm by hibernate.
the class AnnotationBinder method makeInheritanceJoinColumns.
private static AnnotatedJoinColumn[] makeInheritanceJoinColumns(XClass clazzToProcess, MetadataBuildingContext context, InheritanceState inheritanceState, PersistentClass superEntity) {
AnnotatedJoinColumn[] inheritanceJoinedColumns = null;
final boolean hasJoinedColumns = inheritanceState.hasParents() && InheritanceType.JOINED == inheritanceState.getType();
if (hasJoinedColumns) {
// @Inheritance(JOINED) subclass need to link back to the super entity
PrimaryKeyJoinColumns jcsAnn = clazzToProcess.getAnnotation(PrimaryKeyJoinColumns.class);
boolean explicitInheritanceJoinedColumns = jcsAnn != null && jcsAnn.value().length != 0;
if (explicitInheritanceJoinedColumns) {
int nbrOfInhJoinedColumns = jcsAnn.value().length;
PrimaryKeyJoinColumn jcAnn;
inheritanceJoinedColumns = new AnnotatedJoinColumn[nbrOfInhJoinedColumns];
for (int colIndex = 0; colIndex < nbrOfInhJoinedColumns; colIndex++) {
jcAnn = jcsAnn.value()[colIndex];
inheritanceJoinedColumns[colIndex] = AnnotatedJoinColumn.buildJoinColumn(jcAnn, null, superEntity.getIdentifier(), null, null, context);
}
} else {
PrimaryKeyJoinColumn jcAnn = clazzToProcess.getAnnotation(PrimaryKeyJoinColumn.class);
inheritanceJoinedColumns = new AnnotatedJoinColumn[1];
inheritanceJoinedColumns[0] = AnnotatedJoinColumn.buildJoinColumn(jcAnn, null, superEntity.getIdentifier(), null, null, context);
}
LOG.trace("Subclass joined column(s) created");
} else {
if (clazzToProcess.isAnnotationPresent(PrimaryKeyJoinColumns.class) || clazzToProcess.isAnnotationPresent(PrimaryKeyJoinColumn.class)) {
LOG.invalidPrimaryKeyJoinColumnAnnotation(clazzToProcess.getName());
}
}
return inheritanceJoinedColumns;
}
use of jakarta.persistence.PrimaryKeyJoinColumn in project hibernate-orm by hibernate.
the class AnnotatedJoinColumn method buildJoinColumn.
/**
* Build JoinColumn for a JOINED hierarchy
*/
public static AnnotatedJoinColumn buildJoinColumn(PrimaryKeyJoinColumn pkJoinAnn, JoinColumn joinAnn, Value identifier, Map<String, Join> joins, PropertyHolder propertyHolder, MetadataBuildingContext context) {
final ObjectNameNormalizer normalizer = context.getObjectNameNormalizer();
Column col = identifier.getColumns().get(0);
String defaultName = context.getMetadataCollector().getLogicalColumnName(identifier.getTable(), col.getQuotedName());
if (pkJoinAnn != null || joinAnn != null) {
String colName;
String columnDefinition;
String referencedColumnName;
if (pkJoinAnn != null) {
colName = pkJoinAnn.name();
columnDefinition = pkJoinAnn.columnDefinition();
referencedColumnName = pkJoinAnn.referencedColumnName();
} else {
colName = joinAnn.name();
columnDefinition = joinAnn.columnDefinition();
referencedColumnName = joinAnn.referencedColumnName();
}
final String sqlType;
if (columnDefinition.isEmpty()) {
sqlType = null;
} else {
sqlType = normalizer.toDatabaseIdentifierText(columnDefinition);
}
final String name;
if (colName != null && colName.isEmpty()) {
name = normalizer.normalizeIdentifierQuotingAsString(defaultName);
} else {
name = context.getObjectNameNormalizer().normalizeIdentifierQuotingAsString(colName);
}
return new AnnotatedJoinColumn(sqlType, name, null, false, false, true, true, referencedColumnName, null, joins, propertyHolder, null, null, false, context);
} else {
defaultName = context.getObjectNameNormalizer().normalizeIdentifierQuotingAsString(defaultName);
return new AnnotatedJoinColumn(null, defaultName, null, false, false, true, true, null, null, joins, propertyHolder, null, null, true, context);
}
}
use of jakarta.persistence.PrimaryKeyJoinColumn in project hibernate-orm by hibernate.
the class Ejb3XmlOneToOneTest method testMultiplePrimaryKeyJoinColumn.
@Test
public void testMultiplePrimaryKeyJoinColumn() throws Exception {
reader = getReader(Entity1.class, "field1", "one-to-one.orm3.xml");
assertAnnotationPresent(OneToOne.class);
assertAnnotationNotPresent(PrimaryKeyJoinColumn.class);
assertAnnotationPresent(PrimaryKeyJoinColumns.class);
assertAnnotationNotPresent(JoinColumns.class);
assertAnnotationNotPresent(JoinColumn.class);
assertAnnotationNotPresent(JoinTable.class);
PrimaryKeyJoinColumns joinColumnsAnno = reader.getAnnotation(PrimaryKeyJoinColumns.class);
PrimaryKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
assertEquals(2, joinColumns.length);
assertEquals("", joinColumns[0].name());
assertEquals("", joinColumns[0].referencedColumnName());
assertEquals("", joinColumns[0].columnDefinition());
assertEquals("col1", joinColumns[1].name());
assertEquals("col2", joinColumns[1].referencedColumnName());
assertEquals("int", joinColumns[1].columnDefinition());
}
Aggregations