Given are the following two JPA entities:
{code:java|title=Event.java} @Entity public class Event {
@Id @GeneratedValue(strategy = GenerationType.AUTO) @Access(AccessType.PROPERTY) private Long id;
@ElementCollection private Set<Tag> tags; // … getters and setters …
} {code}
{code:java|title=Tag.java} @Embeddable public class Tag {
@Column(nullable = false) private String value;
// … getters and setters …
} {code}
It seems that Hibernate disregards the {{@Column(nullable = false)}} annotation on {{Tag.value}} if and only if {{Event.id}} is annotated with {{@Access(AccessType.PROPERTY)}}.
I published a minimal test case on [https://github.com/bwaldvogel/hibernate-element-collection-access-type-issue]. {{EventTest.testPersistInvalidTag()}} fails on the assertion (unexpected) if and only if {{@Access(AccessType.PROPERTY)}} is used on {{Event.id}}. |
|