From: Jeremy N. (JIRA) <no...@at...> - 2006-05-17 01:26:18
|
[ http://opensource.atlassian.com/projects/hibernate/browse/ANN-293?page=comments#action_23112 ] Jeremy Norris commented on ANN-293: ----------------------------------- The checkin for this fix (http://fisheye.jboss.org/changelog/Hibernate?cs=9837) seems to have caused this issue: http://forum.hibernate.org/viewtopic.php?t=959542 It seemed like a valid thing to be able to map @OneToMany to an @Embeddable type. Thoughts? > Unidirectional @ManyToMany should throw and error or warning when target entity cannot be resolved > -------------------------------------------------------------------------------------------------- > > Key: ANN-293 > URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-293 > Project: Hibernate Annotations > Type: Improvement > Versions: 3.1beta9 > Environment: WinXP, MySQL 4.x / 5.x, JDK 1.5_06 > Reporter: Erik G > Assignee: Emmanuel Bernard > Fix For: 3.2.0.cr1 > > > 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: > @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/silent-column-changes.html ] > Looking through the documentation for Annotations for @ManyToMany at http://www.hibernate.org/hib_docs/annotations/reference/en/html/entity.html#entity-mapping-association-collections > I tried changing my mapping to just: > @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. > see original forum posting: http://forum.hibernate.org/viewtopic.php?t=957121 -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |