Hibernate @IdClass @EmbeddedID相关注解
来源:互联网 发布:阿里云 克隆实例 编辑:程序博客网 时间:2024/04/27 14:10
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.
@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 { ... }
hibernate的annotation的文档中提供了三种方法
1 将组件类注解为@Embeddable,并将组件的属性注解为@Id
2 将组件的属性注解为@EmbeddedId (方便)
3 将类注解为@IdClass,并将该实体中所有属于主键的属性都注解为@Id(符合编程习惯)
主键类需要序列化(考虑到可能会将数据读写到虚拟内存中),需要重写hashcode()和equals()方法,因为要对联合主键进行比较.
Hibernate Annotation 联合主键三种写法的例子:
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
1 0
- Hibernate @IdClass @EmbeddedID相关注解
- JPA 主键@Id、@IdClass、@Embeddable、@EmbeddedId
- 注解开发嵌入式主键@EmbeddedId
- hibernate注解开发相关
- Hibernate基础之六:联合主键@EmbeddedId
- spring整合hibernate配置注解事务的相关问题
- Hibernate初学者---关于annotation注解的相关知识
- @IdClass @IdClass 联合主键的 警告
- hibernate 注解
- hibernate注解
- hibernate注解
- hibernate注解
- Hibernate注解
- Hibernate 注解
- Hibernate注解
- hibernate注解
- hibernate 注解
- hibernate注解
- 快门与曝光
- jQuery easyUI tree
- 设置myeclipse8.5打开默认工作空间
- Go 语言简介(下)— 特性
- java解析json
- Hibernate @IdClass @EmbeddedID相关注解
- Spring使用多个xml配置文件
- 景深
- 今天遇到的问题1
- cognos10.2交叉表隐藏列
- 无聊,写点基础的东西。
- jedis使用pipline的方法
- python3 数字类型常用函数
- Python内建序列之列表