[
http://opensource.atlassian.com/projects/hibernate/browse/ANN-571?page=co...
]
Brian Curnow commented on ANN-571:
----------------------------------
Would you care to explain that? Our annotations appear in the same order on both sides of
the relationship, that's one of the first things we checked when we encountered this
issue.
Regardless of that fact, the spec clearly states that this attribute is required so if it
is missing the behavior is undefined. This should at least generate some sort of log
message. Could you point me to documentation of the correct setup of the annotations or a
description of how Hibernate handles this situation?
This problem with not generating an error is that if you don't have everything setup
exactly right you'll get incorrect results but there won't be a clear indication
of why. We just experienced this behavior in production and it took us hours to determine
that the join was being performed incorrectly and even more time to discover the issue
with our annotations.
I don't think an error is necessary but a warning in the log would be helpful for
diagnostics.
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira