Hibernate annotations Federated primary Key mappings

Source: Internet
Author: User

There are three main ways of using Hibernate annotations for federated primary keys:
First, the field of the Federated primary key is placed in a single class, which needs to implement the Java.io.Serializable interface and override Equals and Hascode, then annotate the class as @embeddable, and finally in the main class (the class does not contain fields from the Federated primary Key Class) Save a reference to the Federated primary key class and generate the set and get methods, and annotate the reference as @id
Second, the field of the Federated primary key is placed in a single class, which needs to implement the Java.io.Serializable interface and override Equals and Hascode, and finally save a reference to the Federated primary key class in the main class (the class does not contain a field in the Federated primary Key Class). and generate the set and get methods, and annotate the reference as @embeddedid
Third, place the fields of the Federated primary key in a single class, which requires implementing the Java.io.Serializable interface and overriding Equals and hashcode. Finally, in the main class, which contains the fields in the Federated primary Key class, the Federated primary key field is annotated as @id. And above this class will be such annotations: @IdClass (Union primary key class. Class)

     Public classBmrorolerightmatrixpkImplementsserializable{Private Static Final LongSerialversionuid = 1L; PrivateLong Actid;//Feature Action ID        PrivateLong Roleid;//role ID@Column (Name= "act_id", unique =false, nullable =true, length = 10)           PublicLong Getactid () {returnActid; }           Public voidSetactid (Long actid) { This. Actid =Actid; } @Column (Name= "role_id", unique =false, nullable =true, length = 10)           PublicLong Getroleid () {returnRoleid; }           Public voidSetroleid (Long roleid) { This. Roleid =Roleid; }                          }  

@Entity @IdClass (bmrorolerightmatrixpk.class) @Table (name= "Bm_ro_rolerightmatrix")       Public classBmrorolerightmatrixImplementsserializable{Private Static Final LongSerialversionuid = 1L;  PublicBmrorolerightmatrix () {}//Properties        PrivateLong Actid;//Feature Action ID              PrivateLong Roleid;//role ID@Id PublicLong Getactid () {return  This. Actid; } @Id PublicLong Getroleid () {return  This. Roleid; }      ...  

 Public classWalletbalanceidImplementsserializable{/**     *      */    Private Static Final LongSerialversionuid = -6967634249077311858l; /*** * CID customer number*/@ManyToOne @JoinColumn (name= "CID")    Privatecustomer customer; /*** * Banking account*/@Column (Name= "Acct_no")    PrivateString Acctno;  PublicWalletbalanceid () {Super(); }     PublicWalletbalanceid (Customer customer, String acctno) {Super();  This. Customer =customer;  This. Acctno =Acctno; }     PublicCustomer GetCustomer () {returncustomer; }     Public voidSetcustomer (Customer customer) { This. Customer =customer; }     PublicString Getacctno () {returnAcctno; }     Public voidSetacctno (String acctno) { This. Acctno =Acctno; } @Override PublicString toString () {returnReflectiontostringbuilder.tostring ( This, Tostringstyle.short_prefix_style); }}

@Entity @table (name= "T_wallet_balance") @IdClass (Walletbalanceid.class) Public classWalletbalanceImplementsSerializable {/**     *      */    Private Static Final LongSerialversionuid = -4041192003429561466l; /*** * CID (primary key) customer number*/@Id @ManyToOne @JoinColumn (name= "CID")    Privatecustomer customer; /*** * Banking account*/@Id @Column (name= "Acct_no")    PrivateString Acctno; /*** * Total amount*/@Column (Name= "Total_amt")    PrivateBigDecimal Totalamt; /*** * Fund status*/@Column (Name= "Fund_state")    PrivateString fundstate; /*** * Updated date*/@Column (Name= "Upd_date")    PrivateDate upddate;  Publicwalletbalance () {Super(); }     PublicCustomer GetCustomer () {returncustomer; }     Public voidSetcustomer (Customer customer) { This. Customer =customer; }     PublicString Getacctno () {returnAcctno; }     Public voidSetacctno (String acctno) { This. Acctno =Acctno; }     PublicBigDecimal Gettotalamt () {returnTotalamt; }     Public voidSettotalamt (BigDecimal totalamt) { This. Totalamt =Totalamt; }     PublicString getfundstate () {returnfundstate; }     Public voidsetfundstate (String fundstate) { This. fundstate =fundstate; }     PublicDate getupddate () {returnupddate; }     Public voidsetupddate (Date upddate) { This. upddate =upddate; } @Override PublicString toString () {returnReflectiontostringbuilder.tostring ( This, Tostringstyle.short_prefix_style); }}

Hibernate annotations Federated primary Key mappings

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.