Primary key constraint generated for a "Set" based ElementCollection in Hibernate
Issue
-
Defining an
@ElementCollection
with an@Embeddable
type usingjava.util.Set
@Embeddable public class Task implements Serializable { @Column(nullable = false) private String name; .... } @Entity public class Employee ... { ... @ElementCollection @CollectionTable(name = "employee_tasks" ...) private Set<Task> tasks = new HashSet<Task>(); ... }
-
Hibernate generates a primary key constraint on the collection table
create table employee_tasks ( Employee_name varchar(255) not null, name varchar(255) not null, primary key (Employee_name, name) )
-
No primary key constraint is generated when using
java.util.List
Environment
- Red Hat JBoss Enteprise Application Platform (EAP) 7
- Hibernate 5
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.