I have a m:n relationship book - borrow - user, the borrow is the join table.
The tables are given (can not be changed):
- on one side they are used by jdbc app as well.
- on the other side i would like to use them via jpa
book(book_id) - borrow(book_id,used_id) - user(user_id)
used jpa annotations:
User:
@OneToMany(targetEntity=BorrowEntity.class, mappedBy="user")
@JoinColumn(name="USER_ID", referencedColumnName="USER_ID")
private List<BorrowEntity>borrowings;
Book:
@OneToMany(targetEntity=BorrowEntity.class, mappedBy="book")
@JoinColumn(name="BOOK_ID", referencedColumnName="BOOK_ID")
private List<BorrowEntity>borrowings;
My problem is that by the settings above it adds some extra (undesired) fields to the borrow table:
'user_USER_ID' and 'book_BOOK_ID'
How can I configure the jpa annotations to keep just Borrow:user_id,book_id which is enough the many to one ?
Take a look at the picture which tells more: