Quantcast
Viewing latest article 2
Browse Latest Browse All 76

Hibernate-Cannot Save The Child

Hello
I have a problem -I jave many to one relation in database and I can't save many side.
I was trying to found out solution,but I didn't find...
Code:

//OneToMany
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER,mappedBy="owner")
  @Column(nullable = false)
  private Set<Contact> contacts;
//ManyToOne
@ManyToOne(fetch=FetchType.EAGER)
  @JoinColumn(name="user_id", nullable = false )
  private User owner;
 
 
//Attempt save
user.addContact(contact);
userDAO.save(user);

After this table Contact is still null
I was trying also

Code:

contact.setOwner(user);
contactDAO.save(contact);


Viewing latest article 2
Browse Latest Browse All 76

Trending Articles