I couldn’t delete entitys from db. I have two class one of them is receipt and other is serving. Receipt has
@ElementCollection
@OneToMany(cascade={CascadeType.ALL}, orphanRemoval=true)
public List<Serving> servings;
And i’m tring to delete a serving from a controller.
Serving serving = Serving.findById(servID);
serving.delete();
The result is;
Execution exception
PersistenceException occured : org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
Something like:
Since the Receipt is the OO owner of its Servings, from an OO perspective Receipt must know when a Serving is deleted.
Maybe write a finder on Receipt for either a Serving or a servingId.
(Are you sure Servings shouldn’t know about which Receipt it belongs to? – the orphanRemoval seems to indicate that a Serving really belongs to one and only one Receipt)