Hibernate entities used.
There are Address
and Room
entities and apropriate tables in DB.
Address
can have multiple Room
s.
Both tables have address_Id
and customerEmailAddress
These columns are FK
in Room
table,that references to Address
table.
There is already Address
record in DB.
It's needed to add several Rooms to this
Address.
How to organize Hibernate relation with annotations between Address
and Room
, so Room
table to be updated with appropriate attributes from Address:
address_Id
and customerEmailAddress
Java part looks like:
Room room = new Room();
Address addr = someService.getAddressFromSession();
room.add(addr);
entityManager.persist(room);
Room room2 = new Room();
room2.add(addr);
entityManager.persist(room2);
DB outcome (Room table) should be following:
id||addressId|| customerEmailAddress
1 || 3 || mail3@a.com
2 || 3 || mail3@a.com