0

I have a simple question. I have User and Log.

@Entity
public class User {
   @Column
   private String login;
   @Column
   private String password;
}

@Entity
public class Log {
   @Column
   private int type;
   @ManyToOne()
   @JoinColumn(name="user")
   private User user;
}

Problem is, when I want to remove object User, it wont allow me to do it because of com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: **Cannot delete or update a parent row: a foreign key constraint fails**. How to set behaviour to delete all Log objects when removing User ?

s0vet
  • 375
  • 4
  • 8
  • 22

1 Answers1

0

You need bidirectional assotiation. See also this example in stackoverflow.

Community
  • 1
  • 1
njjnex
  • 1,490
  • 13
  • 23
  • I believe that this is not my scenario, because I have only Unidirectional mapping. I have more this problem http://stackoverflow.com/questions/14380167/hibernate-unidirectional-onetomany-delete-violates-constraint-optional-false-a – s0vet Oct 30 '14 at 20:41
  • OK, this is solution for my problem http://stackoverflow.com/questions/7197181/jpa-unidirectional-many-to-one-and-cascading-delete – s0vet Oct 30 '14 at 20:46