Search in sources :

Example 1 with XAnnotatedElement

use of org.hibernate.annotations.common.reflection.XAnnotatedElement in project hibernate-orm by hibernate.

the class InheritanceState method extractInheritanceType.

private void extractInheritanceType() {
    XAnnotatedElement element = getClazz();
    Inheritance inhAnn = element.getAnnotation(Inheritance.class);
    MappedSuperclass mappedSuperClass = element.getAnnotation(MappedSuperclass.class);
    if (mappedSuperClass != null) {
        setEmbeddableSuperclass(true);
        setType(inhAnn == null ? null : inhAnn.strategy());
    } else {
        setType(inhAnn == null ? InheritanceType.SINGLE_TABLE : inhAnn.strategy());
    }
}
Also used : Inheritance(javax.persistence.Inheritance) MappedSuperclass(javax.persistence.MappedSuperclass) XAnnotatedElement(org.hibernate.annotations.common.reflection.XAnnotatedElement)

Example 2 with XAnnotatedElement

use of org.hibernate.annotations.common.reflection.XAnnotatedElement in project hibernate-orm by hibernate.

the class AnnotationBinder method addProperty.

private static int addProperty(PropertyContainer propertyContainer, XProperty property, List<PropertyData> inFlightPropertyDataList, MetadataBuildingContext context) {
    // and if so, skip it..
    for (PropertyData propertyData : inFlightPropertyDataList) {
        if (propertyData.getPropertyName().equals(property.getName())) {
            // EARLY EXIT!!!
            return 0;
        }
    }
    final XClass declaringClass = propertyContainer.getDeclaringClass();
    final XClass entity = propertyContainer.getEntityAtStake();
    int idPropertyCounter = 0;
    PropertyData propertyAnnotatedElement = new PropertyInferredData(declaringClass, property, propertyContainer.getClassLevelAccessType().getType(), context.getBuildingOptions().getReflectionManager());
    /*
		 * put element annotated by @Id in front
		 * since it has to be parsed beforeQuery any association by Hibernate
		 */
    final XAnnotatedElement element = propertyAnnotatedElement.getProperty();
    if (element.isAnnotationPresent(Id.class) || element.isAnnotationPresent(EmbeddedId.class)) {
        inFlightPropertyDataList.add(0, propertyAnnotatedElement);
        /**
			 * The property must be put in hibernate.properties as it's a system wide property. Fixable?
			 * TODO support true/false/default on the property instead of present / not present
			 * TODO is @Column mandatory?
			 * TODO add method support
			 */
        if (context.getBuildingOptions().isSpecjProprietarySyntaxEnabled()) {
            if (element.isAnnotationPresent(Id.class) && element.isAnnotationPresent(Column.class)) {
                String columnName = element.getAnnotation(Column.class).name();
                for (XProperty prop : declaringClass.getDeclaredProperties(AccessType.FIELD.getType())) {
                    if (!prop.isAnnotationPresent(MapsId.class)) {
                        /**
							 * The detection of a configured individual JoinColumn differs between Annotation
							 * and XML configuration processing.
							 */
                        boolean isRequiredAnnotationPresent = false;
                        JoinColumns groupAnnotation = prop.getAnnotation(JoinColumns.class);
                        if ((prop.isAnnotationPresent(JoinColumn.class) && prop.getAnnotation(JoinColumn.class).name().equals(columnName))) {
                            isRequiredAnnotationPresent = true;
                        } else if (prop.isAnnotationPresent(JoinColumns.class)) {
                            for (JoinColumn columnAnnotation : groupAnnotation.value()) {
                                if (columnName.equals(columnAnnotation.name())) {
                                    isRequiredAnnotationPresent = true;
                                    break;
                                }
                            }
                        }
                        if (isRequiredAnnotationPresent) {
                            //create a PropertyData fpr the specJ property holding the mapping
                            PropertyData specJPropertyData = new PropertyInferredData(declaringClass, //same dec
                            prop, // the actual @XToOne property
                            propertyContainer.getClassLevelAccessType().getType(), //TODO we should get the right accessor but the same as id would do
                            context.getBuildingOptions().getReflectionManager());
                            context.getMetadataCollector().addPropertyAnnotatedWithMapsIdSpecj(entity, specJPropertyData, element.toString());
                        }
                    }
                }
            }
        }
        if (element.isAnnotationPresent(ManyToOne.class) || element.isAnnotationPresent(OneToOne.class)) {
            context.getMetadataCollector().addToOneAndIdProperty(entity, propertyAnnotatedElement);
        }
        idPropertyCounter++;
    } else {
        inFlightPropertyDataList.add(propertyAnnotatedElement);
    }
    if (element.isAnnotationPresent(MapsId.class)) {
        context.getMetadataCollector().addPropertyAnnotatedWithMapsId(entity, propertyAnnotatedElement);
    }
    return idPropertyCounter;
}
Also used : MapsId(javax.persistence.MapsId) XProperty(org.hibernate.annotations.common.reflection.XProperty) EmbeddedId(javax.persistence.EmbeddedId) MapKeyJoinColumns(javax.persistence.MapKeyJoinColumns) JoinColumns(javax.persistence.JoinColumns) PrimaryKeyJoinColumns(javax.persistence.PrimaryKeyJoinColumns) XAnnotatedElement(org.hibernate.annotations.common.reflection.XAnnotatedElement) XClass(org.hibernate.annotations.common.reflection.XClass) UniqueConstraint(javax.persistence.UniqueConstraint) Constraint(org.hibernate.mapping.Constraint) ManyToOne(javax.persistence.ManyToOne) OneToOne(javax.persistence.OneToOne) PrimaryKeyJoinColumn(javax.persistence.PrimaryKeyJoinColumn) MapKeyJoinColumn(javax.persistence.MapKeyJoinColumn) JoinColumn(javax.persistence.JoinColumn) MapKeyColumn(javax.persistence.MapKeyColumn) OrderColumn(javax.persistence.OrderColumn) PrimaryKeyJoinColumn(javax.persistence.PrimaryKeyJoinColumn) MapKeyJoinColumn(javax.persistence.MapKeyJoinColumn) Column(javax.persistence.Column) DiscriminatorColumn(javax.persistence.DiscriminatorColumn) JoinColumn(javax.persistence.JoinColumn) MapsId(javax.persistence.MapsId) NaturalId(org.hibernate.annotations.NaturalId) EmbeddedId(javax.persistence.EmbeddedId) Id(javax.persistence.Id) CollectionId(org.hibernate.annotations.CollectionId)

Aggregations

XAnnotatedElement (org.hibernate.annotations.common.reflection.XAnnotatedElement)2 Column (javax.persistence.Column)1 DiscriminatorColumn (javax.persistence.DiscriminatorColumn)1 EmbeddedId (javax.persistence.EmbeddedId)1 Id (javax.persistence.Id)1 Inheritance (javax.persistence.Inheritance)1 JoinColumn (javax.persistence.JoinColumn)1 JoinColumns (javax.persistence.JoinColumns)1 ManyToOne (javax.persistence.ManyToOne)1 MapKeyColumn (javax.persistence.MapKeyColumn)1 MapKeyJoinColumn (javax.persistence.MapKeyJoinColumn)1 MapKeyJoinColumns (javax.persistence.MapKeyJoinColumns)1 MappedSuperclass (javax.persistence.MappedSuperclass)1 MapsId (javax.persistence.MapsId)1 OneToOne (javax.persistence.OneToOne)1 OrderColumn (javax.persistence.OrderColumn)1 PrimaryKeyJoinColumn (javax.persistence.PrimaryKeyJoinColumn)1 PrimaryKeyJoinColumns (javax.persistence.PrimaryKeyJoinColumns)1 UniqueConstraint (javax.persistence.UniqueConstraint)1 CollectionId (org.hibernate.annotations.CollectionId)1