You can define multiple @Id
properties in the entity class. like
@Entity
class User implements Serializable {
@Id
private String userId;
@Id
private String passwordsBack;
..
}
This will only be supported by Hibernate not with JPA. While you try to load this into session, you need to create an instance of User and set the id properties and the call the session.load(User.class, userinstance)
I found this hibernate documentation which will help understanding this. http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/#entity-mapping-identifier Section you need to look for is 2.2.3.2.2. Multiple @Id properties.
EDIT: Just realized that you need the xml description and not the annotation based solution. There might be something similar to this approach. Let me see if I can get you a reference.
Update: If you can change your class MyClass
to implement Serializable
, that will fix the problem and no need to have another public PK class. You need to have the equals
and hashCode
methods which will use you id fields.