Home @ManyToOne mapping with @JoinTable gets a foreign key constraint error
Reply: 0

@ManyToOne mapping with @JoinTable gets a foreign key constraint error

user939
1#
user939 Published in April 25, 2018, 6:10 pm

I have a Response entity and every response can have only one user and every user can have many responses. I'm trying to connect it by a lookup table using @JoinTable in Response entity like this:

@ManyToOne()
@JoinTable(
        name = "response_user",
        joinColumns = @JoinColumn(name = "response_id"),
        inverseJoinColumns = @JoinColumn(name = "user_id")
)
@JsonIgnoreProperties({ "firstName", "lastName", "email", "activated", "regDate", "lastVisit" })
private User user;

but I can't delete a user. I'm getting the following error:

Cannot delete or update a parent row: a foreign key constraint fails (`database`.`response_user`, CONSTRAINT `FKf48he1fef6q4d4t3kw4605pfw` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`))

What I would like to achieve is that when the user is deleted, it also deletes everything associated with that user.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.385634 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO