• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

hibernate saving multiple hierarchy records

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have mapping like -

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

getSession().save(OrderData);

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.

Thanks.
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic