Hibernate Annotations
Mapping Composite primary keys and foreign keys to composite primary keys:
http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/#d0e2177
Reference composite primary keys use a embedded class as the primary key representation, so you ' d use the @Id and @Embeddable Annotations. Alternatively, you can use the @EmbeddedId annotation. Note that the dependent class have to is serializable and implements Equals ()/hashcode (). You can also use @IdClass.
@Entitypublic class Regionalarticle implements Serializable { @Id public regionalarticlepk getpk () {...}} @Embeddablepublic class REGIONALARTICLEPK implements Serializable {...}
or alternatively
@Entitypublic class Regionalarticle implements Serializable { @EmbeddedId public regionalarticlepk GETPK () { ... }} public class REGIONALARTICLEPK implements Serializable {...}
three ways are available in Hibernate's annotation documentation
1 Annotate the component class as @embeddable and annotate the properties of the component as @id
2 annotating The properties of a component as @embeddedid (convenient)
3 Annotate the class as @idclass and annotate all properties belonging to the primary key in the entity as @id (conforming toProgramminghabits)
The primary key class needs to be serialized (considering that data may be read and written to virtual memory), and the Hashcode () and Equals () methods need to be rewritten because the federated primary key is to be compared.
Hibernate Annotation Joint primary key three examples of the notation:
http://laodaobazi.iteye.com/blog/903236
which anotation should I use: @IdClass or @EmbeddedId:
Http://stackoverflow.com/questions/212350/which-anotation-should-i-use-idclass-or-embeddedid
Compound Primary Keys with Hibernate and JPA Annotations:
Http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=15usingcompoundprimarykeys
@IdClass and @EmbeddedId:
http://www.coderanch.com/t/452567/ORM/Java/idclass-embeddedid
Hibernate @IdClass @EmbeddedID Related annotations