Search in sources :

Example 1 with SecondaryTables

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;
}
Also used : SecondaryTables(jakarta.persistence.SecondaryTables) SecondaryTable(jakarta.persistence.SecondaryTable)

Example 2 with SecondaryTables

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;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) SecondaryTables(jakarta.persistence.SecondaryTables) ArrayList(java.util.ArrayList) JaxbSecondaryTable(org.hibernate.boot.jaxb.mapping.spi.JaxbSecondaryTable) SecondaryTable(jakarta.persistence.SecondaryTable) JaxbSecondaryTable(org.hibernate.boot.jaxb.mapping.spi.JaxbSecondaryTable) JaxbEntity(org.hibernate.boot.jaxb.mapping.spi.JaxbEntity)

Aggregations

SecondaryTable (jakarta.persistence.SecondaryTable)2 SecondaryTables (jakarta.persistence.SecondaryTables)2 ArrayList (java.util.ArrayList)1 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)1 JaxbEntity (org.hibernate.boot.jaxb.mapping.spi.JaxbEntity)1 JaxbSecondaryTable (org.hibernate.boot.jaxb.mapping.spi.JaxbSecondaryTable)1