Hibernate Federated primary Key annotation configuration

Source: Internet
Author: User

On the internet to see a lot of methods, the results of use or there are some problems. Now, tidy up.

1. Primary KEY class

ImportJavax.persistence.Column; Public classUserroleuionpkImplementsjava.io.Serializable {/**     *      */    Private Static Final LongSerialversionuid = 1L; PrivateString userId; PrivateString Roleid; /*Public USERROLEUIONPK () {super ();        } public USERROLEUIONPK (string userId, String roleid) {This.userid = UserId;    This.roleid = Roleid; }*/@Column (Name= "USER_ID")     PublicString getUserId () {returnuserId; }     Public voidSetuserid (String userId) { This. UserId =userId; } @Column (Name= "role_id")     PublicString Getroleid () {returnRoleid; }     Public voidSetroleid (String roleid) { This. Roleid =Roleid; }    /*@Override public boolean equals (Object o) {if (o instanceof userroleuionpk) {                  USERROLEUIONPK key = (USERROLEUIONPK) o; if (This.getuserid (). Equals (Key.getuserid ()) && This.getroleid (). Equals (Key.getroleid ())) {RET                  Urn true;          }} return false; } @Override public int hashcode () {return This.roleId.hashCode () +this.userid.has          Hcode (); }  */}

Some on the web say that we have to rewrite equals and hashcode, with the structure of the parameter and the parameterless structure, but in fact, I commented it out in the project.

My side of the main focus is @column annotations, did not join the @colunm has been reported that the list of invalid issues.

Entity class

Importjavax.persistence.EmbeddedId;Importjavax.persistence.Entity;Importjavax.persistence.Table; @Entity @table (name= "Sys_user_role") Public classSysuserroleImplementsjava.io.Serializable {PrivateUSERROLEUIONPK UIONPK; @EmbeddedId PublicUSERROLEUIONPK getuionpk () {returnUIONPK; }     Public voidSETUIONPK (userroleuionpk uionpk) { This. UIONPK =UIONPK; }}

2. Primary KEY class

ImportJavax.persistence.Column; Public classUserroleuionpkImplementsjava.io.Serializable {/**     *      */    Private Static Final LongSerialversionuid = 1L; PrivateString userId; PrivateString Roleid; @Column (Name= "USER_ID")     PublicString getUserId () {returnuserId; }     Public voidSetuserid (String userId) { This. UserId =userId; } @Column (Name= "role_id")     PublicString Getroleid () {returnRoleid; }     Public voidSetroleid (String roleid) { This. Roleid =Roleid; }    }

Entity class

Importjavax.persistence.Entity;Importjavax.persistence.Id;ImportJavax.persistence.IdClass;Importjavax.persistence.Table; @Entity @table (name= "Sys_user_role") @IdClass (USERROLEUIONPK.class) Public classSysuserroleImplementsjava.io.Serializable {PrivateString userId; PrivateString Roleid; @Id PublicString getUserId () {returnuserId; }     Public voidSetuserid (String userId) { This. UserId =userId; } @Id PublicString Getroleid () {returnRoleid; }     Public voidSetroleid (String roleid) { This. Roleid =Roleid; }}

Hibernate Federated primary Key annotation configuration

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.