if ( collectionProperty.isAnnotationPresent( MapKeyEnumerated.class ) ) { canKeyBeConverted = false; else if ( collectionProperty.isAnnotationPresent( MapKeyTemporal.class ) ) { canKeyBeConverted = false; else if ( collectionProperty.isAnnotationPresent( MapKeyClass.class ) ) { canKeyBeConverted = false; else if ( collectionProperty.isAnnotationPresent( MapKeyType.class ) ) { canKeyBeConverted = false; if ( collectionProperty.isAnnotationPresent( ManyToAny.class ) ) { canElementBeConverted = false; else if ( collectionProperty.isAnnotationPresent( OneToMany.class ) ) { canElementBeConverted = false; else if ( collectionProperty.isAnnotationPresent( ManyToMany.class ) ) { canElementBeConverted = false; else if ( collectionProperty.isAnnotationPresent( Enumerated.class ) ) { canElementBeConverted = false; else if ( collectionProperty.isAnnotationPresent( Temporal.class ) ) { canElementBeConverted = false; else if ( collectionProperty.isAnnotationPresent( CollectionType.class ) ) { canElementBeConverted = false;
private void validateBind() { if ( property.isAnnotationPresent( Immutable.class ) ) { throw new AnnotationException( "@Immutable on property not allowed. " + "Only allowed on entity level or on a collection." ); } if ( !declaringClassSet ) { throw new AssertionFailure( "declaringClass has not been set before a bind" ); } }
private static boolean hasAnnotationsOnIdClass(XClass idClass) { // if(idClass.getAnnotation(Embeddable.class) != null) // return true; List<XProperty> properties = idClass.getDeclaredProperties( XClass.ACCESS_FIELD ); for ( XProperty property : properties ) { if ( property.isAnnotationPresent( Column.class ) || property.isAnnotationPresent( OneToMany.class ) || property.isAnnotationPresent( ManyToOne.class ) || property.isAnnotationPresent( Id.class ) || property.isAnnotationPresent( GeneratedValue.class ) || property.isAnnotationPresent( OneToOne.class ) || property.isAnnotationPresent( ManyToMany.class ) ) { return true; } } List<XMethod> methods = idClass.getDeclaredMethods(); for ( XMethod method : methods ) { if ( method.isAnnotationPresent( Column.class ) || method.isAnnotationPresent( OneToMany.class ) || method.isAnnotationPresent( ManyToOne.class ) || method.isAnnotationPresent( Id.class ) || method.isAnnotationPresent( GeneratedValue.class ) || method.isAnnotationPresent( OneToOne.class ) || method.isAnnotationPresent( ManyToMany.class ) ) { return true; } } return false; }
private static boolean mustBeSkipped(XProperty property) { //TODO make those hardcoded tests more portable (through the bytecode provider?) return property.isAnnotationPresent( Transient.class ) || "net.sf.cglib.transform.impl.InterceptFieldCallback".equals( property.getType().getName() ) || "org.hibernate.bytecode.internal.javassist.FieldHandler".equals( property.getType().getName() ); } }
private static boolean discoverTypeWithoutReflection(XProperty p) { if ( p.isAnnotationPresent( OneToOne.class ) && !p.getAnnotation( OneToOne.class ) .targetEntity() .equals( void.class ) ) { return true; else if ( p.isAnnotationPresent( OneToMany.class ) && !p.getAnnotation( OneToMany.class ) .targetEntity() .equals( void.class ) ) { return true; else if ( p.isAnnotationPresent( ManyToOne.class ) && !p.getAnnotation( ManyToOne.class ) .targetEntity() .equals( void.class ) ) { return true; else if ( p.isAnnotationPresent( ManyToMany.class ) && !p.getAnnotation( ManyToMany.class ) .targetEntity() .equals( void.class ) ) { return true; else if ( p.isAnnotationPresent( org.hibernate.annotations.Any.class ) ) { return true; else if ( p.isAnnotationPresent( ManyToAny.class ) ) { if ( !p.isCollection() && !p.isArray() ) { throw new AnnotationException( "@ManyToAny used on a non collection non array property: " + p.getName() ); else if ( p.isAnnotationPresent( Type.class ) ) { return true;
private boolean mappingDefinedAttributeOverrideOnMapKey(XProperty property) { if ( property.isAnnotationPresent( AttributeOverride.class ) ) { return namedMapKey( property.getAnnotation( AttributeOverride.class ) ); } if ( property.isAnnotationPresent( AttributeOverrides.class ) ) { final AttributeOverrides annotations = property.getAnnotation( AttributeOverrides.class ); for ( AttributeOverride attributeOverride : annotations.value() ) { if ( namedMapKey( attributeOverride ) ) { return true; } } } return false; }
private void validateLobMappingSupport(XProperty property) { // HHH-9834 - Sanity check try { if ( property.isAnnotationPresent( ElementCollection.class ) ) { if ( property.isAnnotationPresent( Lob.class ) ) { if ( !property.getCollectionClass().isAssignableFrom( Map.class ) ) { throw new MappingException( "@ElementCollection combined with @Lob is only supported for Map collection types." ); } } } } catch ( MappingException e ) { throw new HibernateException( String.format( "Invalid mapping in [%s] for property [%s]", property.getDeclaringClass().getName(), property.getName() ), e ); } }
public XClass getPropertyClass() throws MappingException { if ( property.isAnnotationPresent( Target.class ) ) { return reflectionManager.toXClass( property.getAnnotation( Target.class ).value() ); } else { return property.getType(); } }
public XClass getClassOrElement() throws MappingException { if ( property.isAnnotationPresent( Target.class ) ) { return reflectionManager.toXClass( property.getAnnotation( Target.class ).value() ); } else { return property.getClassOrElementClass(); } }
/** * In case the given annotation is a value generator annotation, the corresponding value generation strategy to be * applied to the given property is returned, {@code null} otherwise. */ private <A extends Annotation> AnnotationValueGeneration<A> getValueGenerationFromAnnotation( XProperty property, A annotation) { ValueGenerationType generatorAnnotation = annotation.annotationType() .getAnnotation( ValueGenerationType.class ); if ( generatorAnnotation == null ) { return null; } Class<? extends AnnotationValueGeneration<?>> generationType = generatorAnnotation.generatedBy(); AnnotationValueGeneration<A> valueGeneration = instantiateAndInitializeValueGeneration( annotation, generationType, property ); if ( annotation.annotationType() == Generated.class && property.isAnnotationPresent( javax.persistence.Version.class ) && valueGeneration.getGenerationTiming() == GenerationTiming.INSERT ) { throw new AnnotationException( "@Generated(INSERT) on a @Version property not allowed, use ALWAYS (or NEVER): " + StringHelper.qualify( holder.getPath(), name ) ); } return valueGeneration; }
public Boolean hasIdClassOrEmbeddedId() { if ( hasIdClassOrEmbeddedId == null ) { hasIdClassOrEmbeddedId = false; if ( getClassWithIdClass( true ) != null ) { hasIdClassOrEmbeddedId = true; } else { final ElementsToProcess process = getElementsToProcess(); for ( PropertyData property : process.getElements() ) { if ( property.getProperty().isAnnotationPresent( EmbeddedId.class ) ) { hasIdClassOrEmbeddedId = true; break; } } } } return hasIdClassOrEmbeddedId; }
private static void setupComponentTuplizer(XProperty property, Component component) { if ( property == null ) { return; } if ( property.isAnnotationPresent( Tuplizers.class ) ) { for ( Tuplizer tuplizer : property.getAnnotation( Tuplizers.class ).value() ) { EntityMode mode = EntityMode.parse( tuplizer.entityMode() ); //todo tuplizer.entityModeType component.addTuplizer( mode, tuplizer.impl().getName() ); } } if ( property.isAnnotationPresent( Tuplizer.class ) ) { Tuplizer tuplizer = property.getAnnotation( Tuplizer.class ); EntityMode mode = EntityMode.parse( tuplizer.entityMode() ); //todo tuplizer.entityModeType component.addTuplizer( mode, tuplizer.impl().getName() ); } }
if ( property.isAnnotationPresent( Id.class ) ) { LOG.debugf( "Skipping AttributeConverter checks for Id attribute [%s]", property.getName() ); return; if ( !key && property.isAnnotationPresent( Temporal.class ) ) { LOG.debugf( "Skipping AttributeConverter checks for Temporal attribute [%s]", property.getName() ); return; if ( key && property.isAnnotationPresent( MapKeyTemporal.class ) ) { LOG.debugf( "Skipping AttributeConverter checks for map-key annotated as MapKeyTemporal [%s]", property.getName() ); return; if ( !key && property.isAnnotationPresent( Enumerated.class ) ) { LOG.debugf( "Skipping AttributeConverter checks for Enumerated attribute [%s]", property.getName() ); return; if ( key && property.isAnnotationPresent( MapKeyEnumerated.class ) ) { LOG.debugf( "Skipping AttributeConverter checks for map-key annotated as MapKeyEnumerated [%s]", property.getName() ); return;
private AccessType determineDefaultAccessType() { for (XClass xclass = clazz; xclass != null; xclass = xclass.getSuperclass()) { if ( ( xclass.getSuperclass() == null || Object.class.getName().equals( xclass.getSuperclass().getName() ) ) && ( xclass.isAnnotationPresent( Entity.class ) || xclass.isAnnotationPresent( MappedSuperclass.class ) ) && xclass.isAnnotationPresent( Access.class ) ) { return AccessType.getAccessStrategy( xclass.getAnnotation( Access.class ).value() ); } } // Guess from identifier. // FIX: Shouldn't this be determined by the first attribute (i.e., field or property) with annotations, but without an // explicit Access annotation, according to JPA 2.0 spec 2.3.1: Default Access Type? for (XClass xclass = clazz; xclass != null && !Object.class.getName().equals(xclass.getName()); xclass = xclass.getSuperclass()) { if ( xclass.isAnnotationPresent( Entity.class ) || xclass.isAnnotationPresent( MappedSuperclass.class ) ) { for ( XProperty prop : xclass.getDeclaredProperties( AccessType.PROPERTY.getType() ) ) { final boolean isEmbeddedId = prop.isAnnotationPresent( EmbeddedId.class ); if ( prop.isAnnotationPresent( Id.class ) || isEmbeddedId ) { return AccessType.PROPERTY; } } for ( XProperty prop : xclass.getDeclaredProperties( AccessType.FIELD.getType() ) ) { final boolean isEmbeddedId = prop.isAnnotationPresent( EmbeddedId.class ); if ( prop.isAnnotationPresent( Id.class ) || isEmbeddedId ) { return AccessType.FIELD; } } } } throw new AnnotationException( "No identifier specified for entity: " + clazz ); }
return property.isAnnotationPresent( ManyToOne.class ) || property.isAnnotationPresent( OneToOne.class );
parent.isOrWithinEmbeddedId() || ( embeddedXProperty != null && ( embeddedXProperty.isAnnotationPresent( Id.class ) || embeddedXProperty.isAnnotationPresent( EmbeddedId.class ) ) ); this.isWithinElementCollection = parent.isWithinElementCollection() || parent instanceof CollectionPropertyHolder;
private static void setVersionInformation(XProperty property, PropertyBinder propertyBinder) { propertyBinder.getSimpleValueBinder().setVersion( true ); if(property.isAnnotationPresent( Source.class )) { Source source = property.getAnnotation( Source.class ); propertyBinder.getSimpleValueBinder().setTimestampVersionType( source.value().typeName() ); } }
Audited allClassAudited, String modifiedFlagSuffix) { Audited aud = ( property.isAnnotationPresent( Audited.class ) ) ? property.getAnnotation( Audited.class ) : allClassAudited;
private void makeOneToManyMapKeyColumnNullableIfNotInProperty( final XProperty property) { final org.hibernate.mapping.Map map = (org.hibernate.mapping.Map) this.collection; if ( map.isOneToMany() && property.isAnnotationPresent( MapKeyColumn.class ) ) { final Value indexValue = map.getIndex(); if ( indexValue.getColumnSpan() != 1 ) { throw new AssertionFailure( "Map key mapped by @MapKeyColumn does not have 1 column" ); } final Selectable selectable = indexValue.getColumnIterator().next(); if ( selectable.isFormula() ) { throw new AssertionFailure( "Map key mapped by @MapKeyColumn is a Formula" ); } Column column = (Column) map.getIndex().getColumnIterator().next(); if ( !column.isNullable() ) { final PersistentClass persistentClass = ( ( OneToMany ) map.getElement() ).getAssociatedClass(); // check if the index column has been mapped by the associated entity to a property; // @MapKeyColumn only maps a column to the primary table for the one-to-many, so we only // need to check "un-joined" properties. if ( !propertyIteratorContainsColumn( persistentClass.getUnjoinedPropertyIterator(), column ) ) { // The index column is not mapped to an associated entity property so we can // safely make the index column nullable. column.setNullable( true ); } } } }
private static void bindCollectionSecondPass( Collection collValue, PersistentClass collectionEntity, Ejb3JoinColumn[] joinColumns, boolean cascadeDeleteEnabled, XProperty property, PropertyHolder propertyHolder, MetadataBuildingContext buildingContext) { try { BinderHelper.createSyntheticPropertyReference( joinColumns, collValue.getOwner(), collectionEntity, collValue, false, buildingContext ); } catch (AnnotationException ex) { throw new AnnotationException( "Unable to map collection " + collValue.getOwner().getClassName() + "." + property.getName(), ex ); } SimpleValue key = buildCollectionKey( collValue, joinColumns, cascadeDeleteEnabled, property, propertyHolder, buildingContext ); if ( property.isAnnotationPresent( ElementCollection.class ) && joinColumns.length > 0 ) { joinColumns[0].setJPA2ElementCollection( true ); } TableBinder.bindFk( collValue.getOwner(), collectionEntity, joinColumns, key, false, buildingContext ); }