Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JPA - Hibernate saving multiple relationship  RSS feed

 
Atul More
Greenhorn
Posts: 24
1
Java jQuery Spring
  • 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
 
Rob Spoor
Sheriff
Posts: 21019
85
Chrome Eclipse IDE Java 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
Greenhorn
Posts: 24
1
Java jQuery Spring
  • 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
Greenhorn
Posts: 24
1
Java jQuery Spring
  • 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
Greenhorn
Posts: 24
1
Java jQuery Spring
  • 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: 21019
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you search on cascadetype jpa you will find several good examples.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!