java - Deleting Objects with JPA with Foreign Key Constraints -


I have two classes, service and customer, I have a customer with a number of customer support from the service and I want to remove any service that refers to it, I am using JPA with ORM (below with hibernation below) attached to a postgrassacul DB.

It would be great if I can define the association in such a way that the removal of the customer is the reference that the service is but that, and maybe I am doing something wrong, because in the service of the Union @ManyToOne Has been defined using, will cascade the customer from operation service, but not in other ways?

Without removing such cascading, I am ready to easily remove all the services that refer to the customer. Easier than JPA / Hibernate, it seems easy to remove the batch and execute them in the wrong order! My code basically asks the customer-related services, calls entityManager.remove () on each, and then calls entityManager.remove () to the customer. But when I flush it, I get an exception that the failure of the customer to be removed due to the foreign key barrier failed.

Should I remove from the service before being removed from the customer? I was not managing the container as my transaction and it would have to do pain in the neck.

Thanks, Andy

Managing constrained relationships is probably a good There is no thought, in particular it is clear that this is a straightforward and standard type of union.

Why do you define a client in which the cascade is specified? (In the link, your service class command will be converted to an example.)


Comments

Popular posts from this blog

MySql variables and php -

c# - How can I find out if there are windows above a control? -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -