Hi all, I'm using EJB3 with its JPA through jboss-4.0.5.GA and it's Hibernate implementation. The experience has been quite good in general, but when trying to insert a record in a @ManyToMany relation an extrange behaviour happens:
Supose A has many B's (and viceversa, but the navigation is A -> B), so If I want to add one B, let's say b, to A's B collection, I would expect to use a.getBs().add(b). The perplexing situation is that Hibernate first deletes all records in a.getBs(), and then inserts all of them again plus the new b record (as if I would had used a.setBs(), in which case is logical). The problem is that in most situations these records can't be deleted due to DB constraints (i.e. referential integrity) so the simple insertion fails.
I'm sure I must be doing something wrong due to my little JPA/Hibernate experience because it does not make sense to me to have to delete when what I really want is to insert!
At the moment the solution was to write an old fashioned SQL navive insert query, not the idea...
Any help would be appreciated,
Leonardo
|