I've been battling configuring a @ManyToMany mapping for several days now and while its still not working, that's not the reason for this post. As I've worked though different issues and different formulations the behavior/reported errors have been very inconsistent.
The weirdest pair of errors was the following:
Undirectional @ManyToMany mapping configured on a domain object. JoinTable configured, but no joinColumn, or inverseJoinColumn configured. Attempt to persist a domain object with the collection attached. Receive an error from the database, some of the columns don't exist. I checked the sql log, yup, its trying to do the right thing, just guessed the wrong column names.
Add the joinColumn and inversionJoinColumn parameters, no other changes. Re-run the test case, now it doesn't even try to hit the database, but gives the "detached entity passed to persist" for the collection type. Tried shutting down and restarting everything, just in case it was a weird caching issue, same behavior. Removed the joinColumn,inverseJoinColumn and its back to hitting the database with the wrong columns.
Is this a bug? Why should providing a column name change the behavoir/determination of if the collection values are detached or not?
I'm planning to try a scaled down version in a test database that exactly follows the expected default hibernate naming strategy to see if it just works in that case, but haven't had the time yet.
Edit:
I've tried the scaled down version with table names/columns that exactly match the hibernate defaults. And now it works. Something seems very odd to me, indeed.
|