Title: ManyToMany forced unique index
Tags: spring;hibernate;jpa;spring-data-jpa;spring-data
Question: I let JPA to create tables. It can create base tables correctly but in the cross table, make one of the join columns unique. In this case, I cannot use as many to many.

Example schema:

Table1: id INT(11);

Table2: id INT(11);

CrossTable: t1id INT(11) nn, t2id INT(11) nn unq; 

Here is the code:

```@ManyToMany
@JoinTable(name = "CrossTable",
        joinColumns = { @JoinColumn(name = "t1id") },
        inverseJoinColumns = { @JoinColumn(name = "t2id") })
@ElementCollection(targetClass=Table2.class)
private List<Table2&gt; datttt;
```

Comment: Annotating a field with ManyToMany and ElementCollection makes no sense. It's one or the other. If Table2 is an entity, then it can't be an ElementCollection. If it's not an entity, then it can't be a ManyToMany. Finally, post the actual table definition being generated, not some pseudo-sql.

Comment: Thanks, deleting @ElementCollection fix it.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:07/28/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<spring><hibernate><jpa><spring-data-jpa><spring-data>', 'Title': 'ManyToMany forced unique index', 'ViewCount': 63, 'id': 51571722, 'user_AboutMe': '', 'user_AccountId': 6356734.0, 'user_DisplayName': 'grnc', 'user_Reputation': 417.0, 'user_Views': 41.0, 'user_id': 4933735.0}}