I know this is very silly question but I am new to hibernate.. I am working on hibernate and In my project I can see there are 2 Entities Suppose A and B and they relation like
Class A{
@ManyToOne
B b;
}
Class B{
@ManyToOne(fetch = FetchType.LAZY)
A a;
}
I am trying to understand why it is so ? why do we need this kind of relation ,is it how we relate foreign key constraint between tables ?
CodePudding user response:
Typically a many to one relationship is if for instance we had 5 children under 1 parent register for a program that makes 5 registrations. They all have registrations but we want them to pay together as one send to our order processor so we don’t hit the card so many times. We will need to extract the amounts and form a many to one relationship before sending this inside our data mapping.
Then we can pass a many to one function or create a table with the relationship as needed conditionally.