Search in sources :

Example 6 with PrimaryKeyJoinColumns

use of javax.persistence.PrimaryKeyJoinColumns in project hibernate-orm by hibernate.

the class AnnotationBinder method makeInheritanceJoinColumns.

private static Ejb3JoinColumn[] makeInheritanceJoinColumns(XClass clazzToProcess, MetadataBuildingContext context, InheritanceState inheritanceState, PersistentClass superEntity) {
    Ejb3JoinColumn[] inheritanceJoinedColumns = null;
    final boolean hasJoinedColumns = inheritanceState.hasParents() && InheritanceType.JOINED.equals(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 Ejb3JoinColumn[nbrOfInhJoinedColumns];
            for (int colIndex = 0; colIndex < nbrOfInhJoinedColumns; colIndex++) {
                jcAnn = jcsAnn.value()[colIndex];
                inheritanceJoinedColumns[colIndex] = Ejb3JoinColumn.buildJoinColumn(jcAnn, null, superEntity.getIdentifier(), null, null, context);
            }
        } else {
            PrimaryKeyJoinColumn jcAnn = clazzToProcess.getAnnotation(PrimaryKeyJoinColumn.class);
            inheritanceJoinedColumns = new Ejb3JoinColumn[1];
            inheritanceJoinedColumns[0] = Ejb3JoinColumn.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;
}
Also used : PrimaryKeyJoinColumn(javax.persistence.PrimaryKeyJoinColumn) PrimaryKeyJoinColumns(javax.persistence.PrimaryKeyJoinColumns) UniqueConstraint(javax.persistence.UniqueConstraint) Constraint(org.hibernate.mapping.Constraint)

Example 7 with PrimaryKeyJoinColumns

use of javax.persistence.PrimaryKeyJoinColumns in project cloudstack by apache.

the class DbUtil method getPrimaryKeyJoinColumns.

public static PrimaryKeyJoinColumn[] getPrimaryKeyJoinColumns(Class<?> clazz) {
    PrimaryKeyJoinColumn pkjc = clazz.getAnnotation(PrimaryKeyJoinColumn.class);
    if (pkjc != null) {
        return new PrimaryKeyJoinColumn[] { pkjc };
    }
    PrimaryKeyJoinColumns pkjcs = clazz.getAnnotation(PrimaryKeyJoinColumns.class);
    if (pkjcs != null) {
        return pkjcs.value();
    }
    return null;
}
Also used : PrimaryKeyJoinColumn(javax.persistence.PrimaryKeyJoinColumn) PrimaryKeyJoinColumns(javax.persistence.PrimaryKeyJoinColumns)

Aggregations

PrimaryKeyJoinColumn (javax.persistence.PrimaryKeyJoinColumn)7 PrimaryKeyJoinColumns (javax.persistence.PrimaryKeyJoinColumns)7 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 CollectionTable (javax.persistence.CollectionTable)1 Entity (javax.persistence.Entity)1 JoinTable (javax.persistence.JoinTable)1 MappedSuperclass (javax.persistence.MappedSuperclass)1 Table (javax.persistence.Table)1 UniqueConstraint (javax.persistence.UniqueConstraint)1 AnnotationException (org.hibernate.AnnotationException)1 BatchSize (org.hibernate.annotations.BatchSize)1 Check (org.hibernate.annotations.Check)1 ForeignKey (org.hibernate.annotations.ForeignKey)1 NaturalIdCache (org.hibernate.annotations.NaturalIdCache)1 OnDelete (org.hibernate.annotations.OnDelete)1 Proxy (org.hibernate.annotations.Proxy)1 Where (org.hibernate.annotations.Where)1 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)1