i have created two seperated class in entity,
varibale declared in user class is :
private Long id;
private String name;
variable declared in book class is:
private Long id;
private String title;
private String author;
private boolean borrowed;
@ManyToOne
@JoinColumn(name = "user_id")
private User borrowedBy;
i cant understand @JoinColumn and what is user_id ? and explain me how @manytoone works?
If you look at the typical JPA logs with Hibernate DDL type of 'create' you can see what is happening behind the scenes:
JPA will create a column (if it doesn't already exist and depending on the DDL type) in your Book table called user_id. This will be the column that holds the identifier to join to the user table.
You can even see that Hibernate creates a foreign key constraint for us auto-magically:
By default, unless specified the user_id column in the book table will contain the primary key values of the user table. In our case, the value defined in the User class id field.
I've included the entities for both User and Book here: