Hibernate inserting into join table
I got several entities. Two of them got a many-to-many relation. When I do a bigger operation on these entities it fails with this exception:
org.hibernate.exception.ConstraintViolationException: could not insert collection rows:
I execute the operation i a @Transactional context. I don't do any explicit flushing i my daos. The flush is triggered by a query. In the queue are 15 elements (all of the same structure). one of them always fails (but it's always a different one (I checked) and always at a different position).
Does anybody have a hint for me for what I might do wrong?
My Mapping:
@ManyToMany(targetEntity = CategoryImpl.class)
protected开发者_高级运维 Set<Category> categories = new HashSet<Category>();
Hard to say with the current level of detail. Is the association bidirectional? Do you have one owning side (with a mappedBy
on the other side) defined? Can you enable logging to see the executed queries and identify the one which is causing the problem.
精彩评论