Search in sources :

Example 1 with JoinColumnsOrFormulas

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

the class ColumnsBuilder method buildExplicitJoinColumns.

Ejb3JoinColumn[] buildExplicitJoinColumns(XProperty property, PropertyData inferredData) {
    //process @JoinColumn(s) beforeQuery @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)

Aggregations

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