[hibernate-issues] [Hibernate-JIRA] Commented: (ANN-571) Missing referencedColumnName in @JoinColumn doesn't cause an error

Brian Curnow (JIRA) noreply at atlassian.com
Tue Mar 13 10:56:09 EDT 2007


    [ http://opensource.atlassian.com/projects/hibernate/browse/ANN-571?page=comments#action_26450 ] 

Brian Curnow commented on ANN-571:
----------------------------------

Ok, I can do that. By "it should explicit the column names" do you mean that Hibernate Tools should add the referencedColumnName attribute?

If not, could you explain how to correctly setup Hibernate Annotations for a multi column join without using referencedColumnName?

> Missing referencedColumnName in @JoinColumn doesn't cause an error
> ------------------------------------------------------------------
>
>          Key: ANN-571
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-571
>      Project: Hibernate Annotations
>         Type: Bug

>     Versions: 3.2.1
>  Environment: Hibernate 3.3.2, Oracle 9.2 (JDBC Thin XA driver version 10.2.0.2.0)
> Running in WebLogic Server 9.2 MP1 on Solaris 8 and JDK 1.5.0_10
>     Reporter: Brian Curnow

>
>
> According to the JPA specification (p. 169) if there are multiple @JoinColumn annotations specified within an @JoinColumns annotation then both name and referencedColumnName attributes must be used: 
> "If there is more than one join column, a JoinColumn annotation must be specified for each join column
> using the JoinColumns annotation. Both the name and the referencedColumnName elements
> must be specified in each such JoinColumn annotation."
> Right now, if I leave off the referencedColumnName everything appears to work but I get some random SQL. For instance, say I have two tables TABLE1 and TABLE2 and they are joined on the columns ID and TYPE, sometimes I get the right join condition:
> TABLE1.ID = TABLE2.ID AND TABLE1.TYPE = TABLE2.TYPE
> but sometimes I get:
> TABLE1.ID = TABLE2.TYPE AND TABLE1.TYPE = TABLE2.ID
> Adding the referencedColumnName makes that issue go away.
> Since the spec says that those two attributes are required there really should be a runtime check for that which, at the very least, puts a warning in the log. I'd prefer a RuntimeException so you can't accidentally violate the spec.

-- 
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




More information about the hibernate-issues mailing list