I've been having moderate success with most of my Hibernate mappings so far (the one caveat on moderate is that I think Hibernate is adding some un-needed outer joins to some fetches, that I'll need to look into at some point)... However, I've been running into some problems with a Many:Many mapping.
The Java end of things seems to be correct; the database tables should be correct. But I'm not sure about my mapping/cascade logic. Its a uni-directional M:M. When I persist the Event object, the collection of Dances are not persisted. What am I missing?
posted 10 years ago
I'm still stumped on this, but I've made some progress.
I've gone back and forth several times between using an explicit join entity(ie having symmetrical ManyToOne's attached to it from both ends of the real relationship) versus the plain M:M.
It seems to be almost working, or at least its no longer silently failing as before. The code is still as shown above, however, there's no longer braces around the joinColumn/inverseJoinColumn values.
I'm testing with a rather simple (but not too useful test)
On the call to makePersistent, I get an exception:
"Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: com.ballroomregistrar.compinabox.data.Dance"
I did a few web-searches and found a few bug reports against 3.2.1.ga (which is what I had been using), that indicated there was a regression from 3.2.0 when creating or updating entities on one side of a M:M if you __replaced__ the collection valued attribute (rather than removing/adding the relevant items). So I switched to the getDances() based calls show above in the test code, instead of the former approach of building a new List and then calling setDances(newList). I've also tried upgrading to the newest version 3.3.1.ga. No luck. Finally I tried downgrading to the 3.2.0.ga version that was reported clear of the issue I thought I was facing. However it still doesn't work, so I suspect I must be in some slightly different error mode.
Can anyone help me?
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database