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

引用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 has to be serializable and implements equals()/hashCode(). You can also use @IdClass.

@Entity
public class RegionalArticle implements Serializable {

    @Id
    public RegionalArticlePk getPk() { ... }
}

@Embeddable
public class RegionalArticlePk implements Serializable { ... }       
or alternatively
@Entity
public class RegionalArticle implements Serializable {

    @EmbeddedId
    public RegionalArticlePk getPk() { ... }
}

public class RegionalArticlePk implements Serializable { ... }

hibernate的annotation的文档中提供了三种方法 
  1 将组件类注解为@Embeddable,并将组件的属性注解为@Id 
  2 将组件的属性注解为@EmbeddedId (方便) 
  3 将类注解为@IdClass,并将该实体中所有属于主键的属性都注解为@Id(符合/IdClass-EmbeddedId 

相关文章:

  • 2021-11-26
  • 2022-01-08
  • 2021-12-19
  • 2022-12-23
  • 2021-07-08
  • 2022-12-23
  • 2022-02-16
  • 2021-12-29
猜你喜欢
  • 2022-12-23
  • 2022-03-01
  • 2021-06-14
  • 2022-12-23
  • 2021-08-22
  • 2021-12-13
  • 2022-12-23
相关资源
相似解决方案