Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using OneToOne as OneToMany

 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I'm having a problem with my application. In my application, there are two classes, which are related to each other via a one sided OneToOne relationship like this





Now I have a situation in which two rows of First have to refer to the same data of the class Second. So what I want to know is that can I use the same Second object with two First objects like this



If this will not create any problems. I'm not sure that this code might even create two copies of the Second object in the database ...
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4680
329
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit,

Your code works fine as you expected. It is a responsibility of the JPA to read the entity and persist the data to the database. Even though the "sec" object is managed in the persistence context, you can use it to refer the same relationship again and again.

Devaka.
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh Great! Thanks Devaka for confirming that
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic