Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

java - How is a `OneToMany` relationship between entities defined in JPA Hibernate?

My Requirements:

I have to save user information along with permissions associated with related markets and stores.

For Example:

User Details:

  • Username
  • Admin
  • Area
  • List
  • List

Markets:

  • Market Name
  • Permission

Stores:

  • Store id
  • Permission

And the end results in the database must be saved as follows:

Profile - Table:

Profile_ID   Profile_Name   Admin   Area      Email_ID              
1            xyz            TRUE    Store     [email protected]
2            abc            FALSE   WareHse   [email protected]

Market- Table:

MKT_ID  MKT_NAME    Permission  Profile_ID
101     Bangalore   view        1
102     Hyderabad   approve     1
101     Bangalore   approve     2
102     Hyderabad   approve     2

Store - Table:

Store_ID      Store Name    Permission  MKT_ID  Profile_ID
1001            B-AAA       View        101  1
1002            B-BBB       View        101  1
2001            H-AAA       approve     102  1
2002            H-BBB       approve     102  1
1001            B-AAA       approve     101  2
1002            B-BBB       approve     101  2
2001            H-AAA       approve     102  2
2002            H-BBB       approve     102  2

With the following additional requirement points:

  • Profile -> Market is a OneToMany entity relationship,
  • Market -> Store is a OneToMany entity relationship
  • In my example there are two markets i.e. Bangalore and Hyderabad and Bangalore and Hyderabad has two stores respectively. So while saving one profile record two markets records will be saved and four profile records will be saved.
  • If the same markets or same store is found for a existing user it will update the record rather than creating a new record across all the tables.

Any help with the: Save, Update and Delete database operations across all scenarios will be very much appreciated.

I tried the following approach.

question from:https://stackoverflow.com/questions/65859396/how-is-a-onetomany-relationship-between-entities-defined-in-jpa-hibernate

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...