I am using EclipseLink as JPA Provider. I want Eclipse Link to Generate my tables so I have used drop-and-create-tables as eclipse link ddl generation strategy in persistence.xml file.
My Question is as follows :
I want to implement Many to Many relationship.I have an auction table and an item table.
An auction can have many items and one item can be in many auctions.
When Eclipse Link Generated the tables, I saw that it had created four tables in the DB.
1) Auction 2) Auction_item 3) Item and 4) Item_auction.
Auction_item has two columns 1) Auction_id 2) item_id
Item_acution has two columns 1) Item_id 2) auction_id
So in all Eclipse Link has created two bridge tables on its own to map Many To Many relationship.
Can we not have a single bridge table having auction_id, item_id to achieve the same?
If we cannot, What are the reasons?
Thanks
You likely have two @ManyToMany mappings but are missing the mappedby indication on one side. This is used to indicate that one side uses the mapping information contained in the other side, and that the relationship is controlled at the database level by that side.
ie: