use of jakarta.persistence.SecondaryTables in project hibernate-orm by hibernate.
the class EntityBinder method findMatchingSecondaryTable.
private SecondaryTable findMatchingSecondaryTable(Join join) {
final String nameToMatch = join.getTable().getQuotedName();
SecondaryTable secondaryTable = annotatedClass.getAnnotation(SecondaryTable.class);
if (secondaryTable != null && nameToMatch.equals(secondaryTable.name())) {
return secondaryTable;
}
SecondaryTables secondaryTables = annotatedClass.getAnnotation(SecondaryTables.class);
if (secondaryTables != null) {
for (SecondaryTable secondaryTablesEntry : secondaryTables.value()) {
if (secondaryTablesEntry != null && nameToMatch.equals(secondaryTablesEntry.name())) {
return secondaryTablesEntry;
}
}
}
return null;
}
use of jakarta.persistence.SecondaryTables in project hibernate-orm by hibernate.
the class JPAXMLOverriddenAnnotationReader method getSecondaryTables.
private SecondaryTables getSecondaryTables(ManagedType root, XMLContext.Default defaults) {
List<JaxbSecondaryTable> elements = root instanceof JaxbEntity ? ((JaxbEntity) root).getSecondaryTable() : Collections.emptyList();
List<SecondaryTable> secondaryTables = new ArrayList<>(3);
for (JaxbSecondaryTable element : elements) {
AnnotationDescriptor annotation = new AnnotationDescriptor(SecondaryTable.class);
copyAttribute(annotation, "name", element.getName(), false);
copyAttribute(annotation, "catalog", element.getCatalog(), false);
if (StringHelper.isNotEmpty(defaults.getCatalog()) && StringHelper.isEmpty((String) annotation.valueOf("catalog"))) {
annotation.setValue("catalog", defaults.getCatalog());
}
copyAttribute(annotation, "schema", element.getSchema(), false);
if (StringHelper.isNotEmpty(defaults.getSchema()) && StringHelper.isEmpty((String) annotation.valueOf("schema"))) {
annotation.setValue("schema", defaults.getSchema());
}
buildUniqueConstraints(annotation, element.getUniqueConstraint());
buildIndex(annotation, element.getIndex());
annotation.setValue("pkJoinColumns", buildPrimaryKeyJoinColumns(element.getPrimaryKeyJoinColumn()));
secondaryTables.add(AnnotationFactory.create(annotation));
}
/*
* You can't have both secondary tables in XML and Java,
* since there would be no way to "remove" a secondary table
*/
if (secondaryTables.size() == 0 && defaults.canUseJavaAnnotations()) {
SecondaryTable secTableAnn = getPhysicalAnnotation(SecondaryTable.class);
overridesDefaultInSecondaryTable(secTableAnn, defaults, secondaryTables);
SecondaryTables secTablesAnn = getPhysicalAnnotation(SecondaryTables.class);
if (secTablesAnn != null) {
for (SecondaryTable table : secTablesAnn.value()) {
overridesDefaultInSecondaryTable(table, defaults, secondaryTables);
}
}
}
if (secondaryTables.size() > 0) {
AnnotationDescriptor descriptor = new AnnotationDescriptor(SecondaryTables.class);
descriptor.setValue("value", secondaryTables.toArray(new SecondaryTable[secondaryTables.size()]));
return AnnotationFactory.create(descriptor);
} else {
return null;
}
}
Aggregations