Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many to many relation mapping #216

Open
xjarkrof opened this issue Oct 23, 2013 · 1 comment
Open

Many to many relation mapping #216

xjarkrof opened this issue Oct 23, 2013 · 1 comment
Assignees
Labels
Milestone

Comments

@xjarkrof
Copy link

It seems there is an issue mapping many to many relation like:

@Entity
public class Item {
....
  @ManyToMany(targetEntity = Category.class, fetch = FetchType.LAZY, cascade = {CascadeType.REFRESH})
  @JoinTable(name = "itemCategory",
        joinColumns = {@JoinColumn(name = "itemId", referencedColumnName = "id")},
        inverseJoinColumns = {@JoinColumn(name = "categoryId", referencedColumnName = "id")})
    private List<Category> categories = new ArrayList<Category>();
....
}

and

@Entity
public class Category {
...
    @ManyToMany(targetEntity = Item.class, fetch = FetchType.LAZY, cascade = {CascadeType.REFRESH})
    @JoinTable(name = "itemCategory",
        joinColumns = {@JoinColumn(name = "categoryId", referencedColumnName = "id")},
        inverseJoinColumns = {@JoinColumn(name = "itemId", referencedColumnName = "id")})
    private List<Item> items = new ArrayList<Item>();
...
}

What I believe is completely legal usage case, is causing something like this:

...
Caused by: org.batoo.jpa.parser.MappingException: Duplicate table names JoinTable[itemCategory class entities.Item.categories], JoinTable[itemCategory class entities.Category.items]
    at org.batoo.jpa.core.impl.model.MetamodelImpl.checkTables(MetamodelImpl.java:379)
    at org.batoo.jpa.core.impl.manager.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:157)
    at org.batoo.jpa.core.impl.manager.JtaEntityManagerFactoryImpl.<init>(JtaEntityManagerFactoryImpl.java:80)
    at org.batoo.jpa.core.BatooPersistenceProvider.createContainerEntityManagerFactory(BatooPersistenceProvider.java:72)
    at org.batoo.jpa.core.BatooPersistenceProvider.createContainerEntityManagerFactory(BatooPersistenceProvider.java:44)
...
@xjarkrof xjarkrof reopened this Oct 23, 2013
@asimarslan asimarslan added the bug label Oct 26, 2014
@asimarslan asimarslan added this to the 2.0.1.3 milestone Oct 26, 2014
@asimarslan asimarslan self-assigned this Oct 26, 2014
asimarslan added a commit that referenced this issue Nov 4, 2014
@asimarslan
Copy link
Contributor

I have replicated the issue in 1f87708

BatooJPA enforces the join tables has unique names. But Unidirectional ManyToMany Relationships has common join tables.

Fix : org.batoo.jpa.core.impl.model.MetamodelImpl.checkTables should understand common join tables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants