java - JPA not saving foreign key to @OneToMany relation -
As a JApay provider I am using Spring with Hibernate and one @OneToMany (trying to contact many phone call contacts)
To save the foreign key in the phone number table, I get a contact object with my form in which it has a list of numbers (numbers). The contact is properly formed (by the specified sequence Hibernate brings a PK) phone (NO F) The list is set up with the right PK, but contact is not throwing in the table.
Public category contact device serializable {@OneToMany (mapped = "contact id", cascade = cascade type.l, fetch = fetchType.EAGER) Private list & lt; Phone & gt; PhoneList; } Public-class phone device serializable {@JoinColumn (name = "contact_id", referenced column name = "contact_id") @ManyToOne personal contact contactId; } @Repository @ ("Contact Dao") @ Transcamilial (read-only) public class contact DaoIMPL applies ContactDao {@ Transactional (read = false, spread = promotions. REQUIRES_NEW) public zero save (contact C) {em .persist (c); Em.flush (); }} @ Controller Public Class ContactController {@RequestMapping (value = "/ contact / new", method = RequestMethod.POST) public model and view new contact (contact C) {ModelAndView MV = New ModelAndView ("ContactForm"); ContactDao.save (c); Mv.addObject ("Contact", c); Return MV; Hopefully I get all the relevant bits above, otherwise please tell me.
You have to manage your Java relations. For something like this, you need something: < / P>
@interity public class contacts {@ id private long ID; @OneToMany (cascade = CascadeType.PERSIST, mapped = "contact") Private listing & lt; Phone & gt; phone number; Public Zero Add Phone (PhoneNumber Phone) {If (Phone! = Zero) {If (Phone Number == Free) {phoneNumbers = New Arrestist & lt; Phone & gt; (); } PhoneNumbers.add (phone); Phone.setContact (this); }} ... @Entity public class phone number {@Id Private Long ID; @ManyToOne Personal Contact Contact; ...}
Comments
Post a Comment