diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/AttributeOverride.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/AttributeOverride.java new file mode 100644 index 0000000000..b18e90bbd3 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/AttributeOverride.java @@ -0,0 +1,73 @@ +package org.hibernate.metamodel.source.annotations.attribute; + +import org.jboss.jandex.AnnotationInstance; + +import org.hibernate.AssertionFailure; +import org.hibernate.metamodel.source.annotations.JPADotNames; + +/** + * Contains the information about a single {@link javax.persistence.AttributeOverride}. Instances of this class + * are creating during annotation processing and then applied onto the persistence attributes. + * + * @author Hardy Ferentschik + */ +public class AttributeOverride { + private final ColumnValues columnValues; + private final String attributePath; + + public AttributeOverride(AnnotationInstance attributeOverrideAnnotation) { + this(null, attributeOverrideAnnotation); + } + + public AttributeOverride(String prefix, AnnotationInstance attributeOverrideAnnotation) { + if ( attributeOverrideAnnotation != null && !JPADotNames.ATTRIBUTE_OVERRIDE.equals( attributeOverrideAnnotation.name() ) ) { + throw new AssertionFailure( "A @Column annotation needs to be passed to the constructor" ); + } + + + + + columnValues = null; + attributePath = ""; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append( "AttributeOverride" ); + sb.append( "{columnValues=" ).append( columnValues ); + sb.append( ", attributePath='" ).append( attributePath ).append( '\'' ); + sb.append( '}' ); + return sb.toString(); + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + AttributeOverride that = (AttributeOverride) o; + + if ( attributePath != null ? !attributePath.equals( that.attributePath ) : that.attributePath != null ) { + return false; + } + if ( columnValues != null ? !columnValues.equals( that.columnValues ) : that.columnValues != null ) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + int result = columnValues != null ? columnValues.hashCode() : 0; + result = 31 * result + ( attributePath != null ? attributePath.hashCode() : 0 ); + return result; + } +} + + diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/ColumnValues.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/ColumnValues.java index 4a2fd246a2..81107eb10c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/ColumnValues.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/ColumnValues.java @@ -30,7 +30,7 @@ import org.hibernate.AssertionFailure; import org.hibernate.metamodel.source.annotations.JPADotNames; /** - * Container for the properties defined by {@code @Column}. + * Container for the properties defined by {@link javax.persistence.Column}. * * @author Hardy Ferentschik */ @@ -46,7 +46,7 @@ public class ColumnValues { private int precision = 0; private int scale = 0; - public ColumnValues() { + ColumnValues() { this( null ); } @@ -58,6 +58,7 @@ public class ColumnValues { } private void applyColumnValues(AnnotationInstance columnAnnotation) { + // if the column annotation is null we don't have to do anything. Everything is already defaulted. if ( columnAnnotation == null ) { return; } @@ -210,6 +211,66 @@ public class ColumnValues { sb.append( '}' ); return sb.toString(); } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + ColumnValues that = (ColumnValues) o; + + if ( insertable != that.insertable ) { + return false; + } + if ( length != that.length ) { + return false; + } + if ( nullable != that.nullable ) { + return false; + } + if ( precision != that.precision ) { + return false; + } + if ( scale != that.scale ) { + return false; + } + if ( unique != that.unique ) { + return false; + } + if ( updatable != that.updatable ) { + return false; + } + if ( columnDefinition != null ? !columnDefinition.equals( that.columnDefinition ) : that.columnDefinition != null ) { + return false; + } + if ( name != null ? !name.equals( that.name ) : that.name != null ) { + return false; + } + if ( table != null ? !table.equals( that.table ) : that.table != null ) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + ( unique ? 1 : 0 ); + result = 31 * result + ( nullable ? 1 : 0 ); + result = 31 * result + ( insertable ? 1 : 0 ); + result = 31 * result + ( updatable ? 1 : 0 ); + result = 31 * result + ( columnDefinition != null ? columnDefinition.hashCode() : 0 ); + result = 31 * result + ( table != null ? table.hashCode() : 0 ); + result = 31 * result + length; + result = 31 * result + precision; + result = 31 * result + scale; + return result; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ConfiguredClass.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ConfiguredClass.java index 19f09051dc..a6241140c9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ConfiguredClass.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ConfiguredClass.java @@ -146,8 +146,6 @@ public class ConfiguredClass { this.idAttributeMap = new TreeMap(); this.associationAttributeMap = new TreeMap(); - // find transient field and method names - findTransientFieldAndMethodNames(); collectAttributes(); } @@ -244,6 +242,9 @@ public class ConfiguredClass { * Find all attributes for this configured class and add them to the corresponding map */ private void collectAttributes() { + // find transient field and method names + findTransientFieldAndMethodNames(); + // use the class mate library to generic types ResolvedTypeWithMembers resolvedType = context.resolveMemberTypes( context.getResolvedType( clazz ) ); for ( HierarchicType hierarchicType : resolvedType.allTypesAndOverrides() ) {