-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Odd failure modes when using annotations to handle m:m
PostPosted: Wed Mar 26, 2008 1:59 pm 
Newbie

Joined: Thu Dec 09, 2004 12:51 pm
Posts: 7
Location: Boston, MA
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.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 04, 2008 7:09 pm 
Newbie

Joined: Fri Mar 21, 2008 2:20 pm
Posts: 10
Location: London
When using JPA I've never had any problems with many to many. But then again I never specify a join table, or columns, I just let hbm2ddl do it's work.

One gotcha that I discovered while messing around with different annotations, while debugging such problems, is that sometimes changes the annotation will change the column type from PRI to MUL - maybe this occurs in other scenario's too.

So you're pulling your hair trying different annotations, and forgetting to re-create the database schema, so then you're just eating your dog food, and getting no where fast :)

You know the 'deleted object passed to persist' is a classic, but probably nothing interesting in this case. You remove an object from your object graph, then do an update, and you get this message... get your debugger out because some object in the graph still has a reference to the object you are attempting to delete.

If you havea a bi-directional mapping, usually you've forgotten to set the inverse side or the owning side to null.

Andy.

_________________
http:// www.techfoundry.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.