0

I get a referential integrity constraint violation for a JUnit Test. Using playframework and my two entities are as follows.

@Entity
public class User extends Model{

public String email;
public String password;

@OneToOne(mappedBy="user",cascade=CascadeType.ALL)
public Patent patent;

}


@Entity
public class Patent extends Model{


    @OneToOne
    public User user;


}

In my Junit test the following line fails

User.findById(user.id)._delete();


Referential integrity constraint violation: "FK340C82E547140EFE: PUBLIC.PATENT FOREIGN KEY(USER_ID) REFERENCES PUBLIC.USER(ID)"; SQL statement:
delete from User where id=? [23003-149]

Thank you

smk
  • 5,340
  • 5
  • 27
  • 41

1 Answers1

0

You should only use one @OneToOne annotation on the owner of the relationship. In your case the user owns the patent so you can remove the following from your Patent entity:


    @OneToOne
    public User user;

Try this with delete again.

emt14
  • 4,846
  • 7
  • 37
  • 58