The code involved:
Class:org.hibernate.metamodel.source.annotations.attribute.ColumnValues
Method: applyColumnValues(AnnotationInstance)
Line 71 (according to the source attached to version 4.2.2.Final using ivy/maven):
AnnotationValue uniqueValue = columnAnnotation.value( "unique" );
if ( uniqueValue != null ) {
this.unique = nameValue.asBoolean();
}
Where nameValue should be uniqueValue.
This stops me from using the annotation:
@Column(name = "code", unique = true, nullable = false, length = 50)
The workaround is probably adding a unique-index using the @NaturalId, but this is non-standard.
(As this is only a copy/paste mistake I ticked the box 'Suitable for new contributors')
In a JBoss 7.1 type environment and with org.jboss.jandex.AnnotationValue.asBoolean in my class-path somehow. This might mean that when jandex is not there the alternative might be more forgiving towards the asBoolean which would then hide the mistake in org.hibernate.metamodel.source.annotations.attribute.ColumnValues
I now use the other way of making the field unique: using the @Table annotation combined with the @UniqueConstraint annotation:
which is more flexible (one can use multiple columns and one can specify a name of the index) and which is probably used more. But it's still a simple copy/paste mistake that would be nice to get rid of.
I moved this bug to the ORM project as I suspect that's what you are using.
I would say this could also land in a 4.x.x bug-fix release, or am I wrong?
Using the new metamodel is not yet supported – the code in the master branch (4.3.x) is stale by several months. The metamodel branch will be 5.0.0.
This is already corrected in the metamodel branch: