• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EntityManager persist problem in oneToMany relation

 
Juan Porras Antonio
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, guys, good afternoon from Spain.

I need an example to do OneToMany persistence with EntityManager, my exercise doesn't work.

I have a class, Person, with ID, name and Set of Phones.

In the other side, I have a class called Phone, which contains ID, phoneNumber and FK_phone.

First question:
Do I need create ForeignKey in MySQL database?.

Second Question:
Does EntityManager persist with OneToMany?. My example saves Person, but not Phones when I do em.persist(Person).
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It all depends on the cascade option you set to the Collection of Phones inside the Person object.

Show us your Person mapping.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic