Search in sources :

Example 1 with JoinFormula

use of org.hibernate.annotations.JoinFormula in project hibernate-orm by hibernate.

the class ColumnsBuilder method buildExplicitJoinColumns.

Ejb3JoinColumn[] buildExplicitJoinColumns(XProperty property, PropertyData inferredData) {
    // process @JoinColumn(s) before @Column(s) to handle collection of entities properly
    JoinColumn[] joinColumnAnnotations = null;
    if (property.isAnnotationPresent(JoinColumn.class)) {
        joinColumnAnnotations = new JoinColumn[] { property.getAnnotation(JoinColumn.class) };
    } else if (property.isAnnotationPresent(JoinColumns.class)) {
        JoinColumns joinColumnAnnotation = property.getAnnotation(JoinColumns.class);
        joinColumnAnnotations = joinColumnAnnotation.value();
        int length = joinColumnAnnotations.length;
        if (length == 0) {
            throw new AnnotationException("Cannot bind an empty @JoinColumns");
        }
    }
    if (joinColumnAnnotations != null) {
        return Ejb3JoinColumn.buildJoinColumns(joinColumnAnnotations, null, entityBinder.getSecondaryTables(), propertyHolder, inferredData.getPropertyName(), buildingContext);
    }
    JoinColumnOrFormula[] joinColumnOrFormulaAnnotations = null;
    if (property.isAnnotationPresent(JoinColumnOrFormula.class)) {
        joinColumnOrFormulaAnnotations = new JoinColumnOrFormula[] { property.getAnnotation(JoinColumnOrFormula.class) };
    } else if (property.isAnnotationPresent(JoinColumnsOrFormulas.class)) {
        JoinColumnsOrFormulas joinColumnsOrFormulasAnnotations = property.getAnnotation(JoinColumnsOrFormulas.class);
        joinColumnOrFormulaAnnotations = joinColumnsOrFormulasAnnotations.value();
        int length = joinColumnOrFormulaAnnotations.length;
        if (length == 0) {
            throw new AnnotationException("Cannot bind an empty @JoinColumnsOrFormulas");
        }
    }
    if (joinColumnOrFormulaAnnotations != null) {
        return Ejb3JoinColumn.buildJoinColumnsOrFormulas(joinColumnOrFormulaAnnotations, null, entityBinder.getSecondaryTables(), propertyHolder, inferredData.getPropertyName(), buildingContext);
    }
    if (property.isAnnotationPresent(JoinFormula.class)) {
        JoinFormula ann = property.getAnnotation(JoinFormula.class);
        Ejb3JoinColumn[] ejb3JoinColumns = new Ejb3JoinColumn[1];
        ejb3JoinColumns[0] = Ejb3JoinColumn.buildJoinFormula(ann, null, entityBinder.getSecondaryTables(), propertyHolder, inferredData.getPropertyName(), buildingContext);
        return ejb3JoinColumns;
    }
    return null;
}
Also used : JoinFormula(org.hibernate.annotations.JoinFormula) JoinColumn(javax.persistence.JoinColumn) JoinColumnOrFormula(org.hibernate.annotations.JoinColumnOrFormula) JoinColumns(javax.persistence.JoinColumns) AnnotationException(org.hibernate.AnnotationException) JoinColumnsOrFormulas(org.hibernate.annotations.JoinColumnsOrFormulas)

Example 2 with JoinFormula

use of org.hibernate.annotations.JoinFormula in project hibernate-orm by hibernate.

the class Ejb3JoinColumn method buildJoinColumnsOrFormulas.

public static Ejb3JoinColumn[] buildJoinColumnsOrFormulas(JoinColumnOrFormula[] anns, String mappedBy, Map<String, Join> joins, PropertyHolder propertyHolder, String propertyName, MetadataBuildingContext buildingContext) {
    Ejb3JoinColumn[] joinColumns = new Ejb3JoinColumn[anns.length];
    for (int i = 0; i < anns.length; i++) {
        JoinColumnOrFormula join = anns[i];
        JoinFormula formula = join.formula();
        if (formula.value() != null && !formula.value().equals("")) {
            joinColumns[i] = buildJoinFormula(formula, mappedBy, joins, propertyHolder, propertyName, buildingContext);
        } else {
            joinColumns[i] = buildJoinColumns(new JoinColumn[] { join.column() }, mappedBy, joins, propertyHolder, propertyName, buildingContext)[0];
        }
    }
    return joinColumns;
}
Also used : JoinFormula(org.hibernate.annotations.JoinFormula) JoinColumnOrFormula(org.hibernate.annotations.JoinColumnOrFormula)

Aggregations

JoinColumnOrFormula (org.hibernate.annotations.JoinColumnOrFormula)2 JoinFormula (org.hibernate.annotations.JoinFormula)2 JoinColumn (javax.persistence.JoinColumn)1 JoinColumns (javax.persistence.JoinColumns)1 AnnotationException (org.hibernate.AnnotationException)1 JoinColumnsOrFormulas (org.hibernate.annotations.JoinColumnsOrFormulas)1