[hibernate-issues] [Hibernate-JIRA] Created: (ANN-756) @Column annotation ignored when placed on entity's @Id property

sagi mann (JIRA) noreply at atlassian.com
Wed Jun 25 05:46:19 EDT 2008


@Column annotation ignored when placed on entity's @Id property
---------------------------------------------------------------

                 Key: ANN-756
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-756
             Project: Hibernate Annotations
          Issue Type: Bug
    Affects Versions: 3.3.1.GA
         Environment: hib core 3.2.6, my sql 5
            Reporter: sagi mann


Hibernate docs specify that when using a compound key class, a Hibernate optional feature is to place @Column annotations within the key class. The observed behavior is that Hibernate ignores @Column if placed ANYWHERE ELSE, for example, on the entity's ID properties. In other words, the standard JPA way of annotating ID fields is not working under Hibernate, and the "optional" feature is mandatory.

Example how to reproduce (see comments inside the code regarding the inconsistency above). Accessors were omitted for clarity:

// the identity class 
@Entity 
public class SecurityIdentity implements Serializable { 
    
    public SecurityIdentity() {} 
    
    @Id 
    @Column(name="IDENTITY_ID") 
    @GeneratedValue 
    public Long getId() ... 

    @Column(name="IDENTITY_NAME") 
    public String getName() ... 
    
    @Override public boolean equals(Object o) ... 
    @Override public int hashCode() ... 
} 


// the domain class 
@Entity 
public class SecurityDomain implements Serializable { 
    
    public SecurityDomain() {} 
    
    @Id 
    @Column(name="DOMAIN_ID") 
    @GeneratedValue 
    public Long getId() ... 

    @Column(name="DOMAIN_NAME") 
    public String getName() ... 
    
    @Override public boolean equals(Object o) ... 
    @Override public int hashCode() ... 
} 



// the domain-identity mapping class 
@Entity 
@IdClass(pu1.DomainIdentityPK.class) 
public class DomainIdentity implements Serializable { 
    
    public DomainIdentity() {} 

    @Id 
    public Long getDomainId() ... 

    @Id 
    public String getUserAlias() ...    

    @ManyToOne 
    @JoinColumn(name="IDENTITY_ID") 
    public SecurityIdentity getSecurityIdentity() ... 

    @ManyToOne 
    @JoinColumn(name="DOMAIN_ID", insertable=false, updatable=false) 
    public SecurityDomain getSecurityDomain() { return securityDomain; } 
    public void setSecurityDomain(SecurityDomain securityDomain) { 
        this.securityDomain = securityDomain; 
        this.domainId = (securityDomain != null ? securityDomain.getId() : null); 
    } 
    private SecurityDomain securityDomain; 
} 


// the map key class 
public class DomainIdentityPK implements Serializable { 
    
    public DomainIdentityPK() { 
    } 
    
    /********* @Column inconsistency - cannot be placed inside the entity - only inside the PK class *******/ 
    @Column(name="DOMAIN_ID") 
    public Long getDomainId() ... 

    [b]@Column(name="ALIAS")[/b] 
    public String getUserAlias() ... 

    public boolean equals(Object o) ... 
    public int hashCode() ... 
} 


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