Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JPA - Hibernate saving multiple relationship

 
Ranch Hand
Posts: 138
1
jQuery Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a question related to data saving in DB using JPA/Hibernate. I have to save data like -
Customer -(1)——(M)-Service-(1)——-(1)-Plan

One customer has many services and each service is associated with single plan.

When I am saving a customer, I have a data related to service and plan as well.

Any pointers??
How to save this relation …??


Atul
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at CascadeMode CascadeType and how they should be set on your @OneToMany and @OneToOne relations.
 
Atul More
Ranch Hand
Posts: 138
1
jQuery Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Rob thanks for ANswer.
Can you please tell me .. how? Some inputs... because I have a  customer, he opt for services i.e. it is a list and each service has a plan associated with it.
So how can I pass this entire relation to DB?
Where I need to put the relation points
 
Atul More
Ranch Hand
Posts: 138
1
jQuery Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Atul More wrote:Hey Rob thanks for ANswer.
Can you please tell me .. how? Some inputs... because I have a  customer, he opt for services i.e. it is a list and each service has a plan associated with it.
Customer, Service and Plan are master tables and I want to save the relation of all these in DB

So how can I pass this entire relation to DB?

Where I need to put the relation points

 
Atul More
Ranch Hand
Posts: 138
1
jQuery Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Atul More wrote:

Atul More wrote:Hey Rob thanks for ANswer.
Can you please tell me .. how? Some inputs... because I have a  customer, he opt for services i.e. it is a list and each service has a plan associated with it.
Service and Plan are master tables and I want to save the relation of all these(Customer -> Service -> Plan) in DB when I create any new customer.

So how can I pass this entire relation to DB?

Where I need to put the relation points

 
Rob Spoor
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you search on cascadetype jpa you will find several good examples.
 
Onion rings are vegetable donuts. Taste this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic