Hibernate does not honor @Column(name=...) annotation with IdClass
------------------------------------------------------------------
Key: ANN-685
URL:
http://opensource.atlassian.com/projects/hibernate/browse/ANN-685
Project: Hibernate Annotations
Issue Type: Bug
Affects Versions: 3.2.1
Environment: Hibernate 3.2.1, JBoss 4.0.4
Reporter: Steve Devore
When an Entity uses an IdClass, any query will fail fails because it is using the name of
the attribute instead of the one indicated by the @Column annotation. It fails because
it is looking for the annotations of the IdClass instead of the main class.
Please see the following example:
The IdClass is defined as follows:
public class DomainAdminId implements Serializable {
private String domainName;
private String adminUser;
public DomainAdminId() {
}
public DomainAdminId(String domainName, String adminUser) {
this.domainName = domainName;
this.adminUser = adminUser;
}
public String getDomainName() {
return domainName;
}
public void setDomainName(String domainName) {
this.domainName = domainName;
}
public String getAdminUser() {
return adminUser;
}
public void setAdminUser(String adminUser) {
this.adminUser = adminUser;
}
public boolean equals(Object o) {
return ((o instanceof DomainAdminId) &&
domainName.equals(((DomainAdminId)o).getDomainName()) &&
adminUser.equals(((DomainAdminId)o).getAdminUser()));
}
public int hashCode() {
return (domainName+adminUser).hashCode();
}
}
And the following Entity using that idClass:
@Entity
@Table(name="domainadmin")
@IdClass(DomainAdminId.class)
@NamedQueries( {
@NamedQuery(name = "DomainAdmin.test", query = "SELECT d FROM DomainAdmin
d")
)
public class DomainAdmin implements Serializable {
@Id
@Column(name="domain_name")
private String domainName;
@Id
@Column(name="adminuser")
private String adminUser;
public DomainAdmin() {
}
public String getDomainName() {
return domainName;
}
public void setDomainName(String domainName) {
this.domainName = domainName;
}
public String getAdminUser() {
return adminUser;
}
public void setAdminUser(String adminUser) {
this.adminUser = adminUser;
}
}
When executing the DomainAdmin.test Named Query I got this error:
could not execute query [select domainadmi0_.adminUser as adminUser1_,
domainadmi0_.domainName as domainName1_ from domainadmin domainadmi0_]
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column
'domainadmi0_.domainName' in 'field list'
In effect, as indicated in the source, the column name is "domain_name" and not
"domainName".
The same apply for the other column: adminUser (that should instead be
"adminuser"),
Workaround:
If the @Column annotation is put on the IdClass it will work sucessfully. However, this
should not be necessary.
--
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