-7
How do I, by Annotations or methods to delete, or effect a update
in a parent entity without being obliged to exclude the daughter entity, ex:
public class Produto{
@Id
@GeneratedValue
int id;
//...
@ManyToOne() //fetch.LAZY
Categoria categoria;
}
public class Categoria{
@Id
@GeneratedValue
int id;
//...
@OneToMany(mappedby = "categoria") //fetch.LAZY
Produto produto;
}
We see that my class produto
is the daughter class of the operation, the stronger side, which holds the foreign key
category, I would like to be able to delete a category, even if it is related to a product, by updating the column CATEGORIA_ID
from table to NULL
maybe.
But when I try to delete it makes an error:
Constraintviolationexception It is not possible to delete or update a record that has a relationship.
I’ve tried the property ORPHANREMOVAL = FALSE
and nothing.
Don’t write in capital letters, because it gives the impression that you are SCREAMING.
– Piovezan
Please edit your question to make it clearer and readable, I suggest you read how to format your question
– Lucas Duete
sorry friends, I won’t do it again.
– Gabriel Martins