Re: JPA schema creation : Unique index on foreign-keys


Debugging the schema creation, the unique constraint is added by TableImpl:createCandidateKeys.
When a OneToOne doesn't have mapped-by parameter, it is considered as unique. The JPAAnnotationReader makes foreign-key unique by default in such situation (unidirectional OneToOne)
Why ? Semantically, the OneToOne relationship also identify both side of the relationship, so having a UNIQUE index is totally correct.

So to map a simple unidirectional association, the solution with JPA is ManyToOne without collection on the other side. May need some clarification on JPA spec (and a tck...).


Join to automatically receive all group messages.