Hibernate Annotations (2)

Source: Internet
Author: User

EmbeddedId)

Master Table


@ Entity
Public class A implements Serializable ...{

@ EmbeddedId
Private AId aId;

Public AId getAId ()...{
Return aId;
    }

Public void setAId (AId aId )...{
This. aId = aId;
    }
}
Composite primary key

 

@ Embeddable
Public class AId implements Serializable ...{

@ OneToOne
@ JoinColumn (name = "bid ")
Private B;

@ OneToOne
@ JoinColumn (name = "cid ")
Private C c;


Public B getB ()...{
Return B;
    }

Public void setB (B B )...{
This. B = B;
    }

Public C getC ()...{
Return c;
    }

Public void setC (C c )...{
This. c = c;
    }
}
Join table

 

@ Entity
Public class B ...{

@ Id
@ GeneratedValue
Private Long id;


Public Long getId ()...{
Return id;
    }

Public void setId (Long id )...{
This. id = id;
    }
}

@ Entity
Public class C ...{

@ Id
@ GeneratedValue
Private Long id;


Public Long getId ()...{
Return id;
    }

Public void setId (Long id )...{
This. id = id;
    }
}
Application of compound primary key (IdClass)

Master Table

 

@ Entity
@ IdClass (OrderLinePk. class)
Public class OrderLine ...{
@ Id
Public Order order;
@ Id
Public Product product;
}
Primary key

 

Public class OrderLinePk implements Serializable ...{
@ ManyToOne
@ JoinColumn (name = "foo", nullable = false)
Public Order order;
@ ManyToOne
@ JoinColumn (name = "bar", nullable = false)
Public Product product;
}

Join table

 

@ Entity
Public class Product ...{
@ Id
Public String name;
}

@ Entity
@ Table (name = "OrderTableFoobar ")
Public class Order ...{
@ Id
@ GeneratedValue
Public Integer id;
}

 

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.