Hibernate @IdClass @EmbeddedID Related annotations

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.