-->
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.  [ 4 posts ] 
Author Message
 Post subject: debugging a bad unidirectional @ManyToMany
PostPosted: Wed Mar 22, 2006 1:51 am 
Newbie

Joined: Fri Feb 10, 2006 2:57 am
Posts: 14
I spent a few hours today tracking down a problem in one of @ManyToMany mappings. I thought I'd share my results here in case anyone runs across the same. I'm using Hibernate 3.1.2, HibAnno 3.1beta8 on MySQL. I also checked this with HibAnno 3.1beta9 which I pulled out of SVN today.

I have a Unidirectional ManyToMany relationship between a User object and a Task object. Task is actually an interface implemented by AbstractTask and extended by UserTask.

My original mapping looks like this:
Code:
@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinTable(name = "user_tasks",
            joinColumns = { @JoinColumn(name = "user_guid") },
            inverseJoinColumns = { @JoinColumn(name = "task_guid") } )
public List<Task> getAvailableTasks() {...}


The correct join table would be created and the "user_guid" column would be created and would be of the correct SQL type for my PK. However, the "task_guid" column would be named "elt" and the sql datatype would be tinyblob (I think Hibernate was probably creating it as a varbinary and MySQL was silently turning it into a tinyblob - see http://dev.mysql.com/doc/refman/5.0/en/ ... anges.html ]

Looking through the documentation for Annotations for @ManyToMany at http://www.hibernate.org/hib_docs/annot ... ollections
I tried changing my mapping to just:
Code:
@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
public List<Task> getAvailableTasks() {...}


This changed the name of my join table per the default naming conventions, but the column names and types were still the same as before.

Next I tried putting in a targetEntity=AbstractTask.class because this is the superclass of my Task class hierarchy. AbstractTask is marked as a @MappedSuperClass. No luck - same results with both permutations of mappings.

The solution: I changed the targetEntity=BaseTask.class which is explicity mapped in hibernate.cfg.xml and the DDL was generated as I expected.

While this is totally user error on my part, it would be nice to have had Annotations throw out an error message or warning of some kind that it would not figure out the targetClass instead of just creating bad DDL and silently ignoring the inverseJoinColumn attribute.

Hopefully this post will save someone else some time in the future.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 25, 2006 9:17 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I like the idea. Open a JIRA issue please. Even better provide a patch :-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject: issue posted
PostPosted: Wed Mar 29, 2006 1:52 am 
Newbie

Joined: Fri Feb 10, 2006 2:57 am
Posts: 14
posted. http://opensource.atlassian.com/project ... se/ANN-293

re: patch - i'll look into it. any pointers on which to look at first would be helpful... also, any tips on which unit tests would be a good starting point.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 31, 2006 7:41 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
unit tests are in org.hibernate.test.annotations.collectionelement
You should probably look into Collectionbinder in the second pass. This is where we defice whether a target entity is an entity or a composite element

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.