[hibernate-issues] [Hibernate-JIRA] Created: (HHH-4819) Hibernate errors when @IdClass class contains "extra" attributes

Steve Ebersole (JIRA) noreply at atlassian.com
Tue Jan 19 11:29:30 EST 2010


Hibernate errors when @IdClass class contains "extra" attributes
----------------------------------------------------------------

                 Key: HHH-4819
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4819
             Project: Hibernate Core
          Issue Type: Bug
          Components: annotations
            Reporter: Steve Ebersole


This is based on an interpretation of wording in the spec.  What the spec says is:
{quote}
If the composite primary key class is represented as an id class, the names of primary key
fields or properties in the primary key class and those of the entity class to which the id class is
mapped must correspond and their types must be the same
{quote}

So imagine an entity such as
{code}
@Entity 
@IdClass(MyEntityPK.class}
class MyEntity {
    @Id Long id1;
    @Id Long id2;
    ...
}
{code}

and 

{code}
class SimplePK implements Serializable {
    private final Long id1;
    private final Long id2;
    private final transient int cachedHashCode;

    public SimplePK(Long id1, Long id2) {
        this.id1 = id1;
        this.id2 = id2;
        this.cachedHashCode = calculateHashCode();
    }

    private int calculateHashCode() {
        ...
    }

    @Override
    public int hashCode() {
        return cachedHashCode;
    }

    ...
}
{code}

This is valid according to the spec.  The entity has 2 attributes marked with @Id.  The "pk class" has 2 attributes that match the types and names of those attributes perfectly as specified by 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