User has many Order
Order has many OrderItem
OrderItem has one Address.
When a user make order - I have to save User, Order, OrderItem, Address in database.
In my DAO, I am saving record for Order as
I have to further save Orderitem and Addresses. Please guide me how do I do save records in OrderItem ? First, should I get id from Order which is just created and then save that in OrderItems. Then get Id for OderItem when it is saved in database and then save Address, etc for that orderitem. Please help.
Hibernate can handle that for you as long as the relationships are defined correctly in the mapping file or if you are using annotations in each entity class.
For example for the relationship between order and order item, using annotations you just have to define the relationship and identify the 1-many relationship using the @JoinColumn and @ManyToOne Annotations. I'd suggest you read up on Hibernate a little.
Bosun (SCJP, SCWCD).
So much trouble in the world -- Bob Marley
That's a very big dog. I think I want to go home now and hug this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth