关于hibernate 注解 OnetoOne 或 ManyToOne 写法
来源:互联网 发布:成都app软件开发 编辑:程序博客网 时间:2024/05/16 06:57
关于hibernate 注解 OnetoOne 或 ManyToOne 写法
- 当主表中有子表的外键。
这种相对简单,直接把主表中子表的id换成子表的实体即可
/*菜品表主键/
/**子表表主键*/// private java.util.Date alDinningCookId; /**替换成子表的实体或者子表的list 取决于一对一 还是一对多/ private AlDinningCookInfoEntity alDinningCookInfoEntity; @OneToOne @JoinColumn(name="al_dinning_cook_id") public AlDinningCookInfoEntity getAlDinningCookInfoEntity() { return alDinningCookInfoEntity; } public void setAlDinningCookInfoEntity( AlDinningCookInfoEntity alDinningCookInfoEntity) { this.alDinningCookInfoEntity = alDinningCookInfoEntity; }
- 主子关联,主表的主键是子表的关联字段
这种相对复杂,需要在两个实体中都标明实体关系
这里有店铺表和店铺详情表,店铺表的为主表,该表的主键出现在它子表店铺详情表中
首先在子表中声明关联主表的实体
/**店铺id*/ //private String alShopId; /**店铺id*/ private AlShopEntity alShopEntity ; @OneToOne @JoinColumn(name="Al_SHOP_ID",insertable=true,unique=true) public AlShopEntity getAlShopEntity() { return alShopEntity; } public void setAlShopEntity(AlShopEntity alShopEntity) { this.alShopEntity = alShopEntity; }
然后在主表中声明关联的子表
/**店铺id*/ private AlShopDetailEntity alShopDetailEntity;//mappedBy="alShopEntity" 写在子表中的实体名称 @OneToOne(mappedBy="alShopEntity",fetch=FetchType.EAGER) public AlShopDetailEntity getAlShopDetailEntity() { return alShopDetailEntity; } public void setAlShopDetailEntity(AlShopDetailEntity alShopDetailEntity) { this.alShopDetailEntity = alShopDetailEntity; }
0 0
- 关于hibernate 注解 OnetoOne 或 ManyToOne 写法
- Hibernate onetomany onetoone manytoone样例
- Hibernate OneToOne注解配置
- Hibernate OneToOne注解配置
- Hibernate OneToOne注解配置
- Hibernate OneToOne注解配置
- Hibernate OneToOne注解
- hibernate onetoone 注解
- Hibernate @OnetoOne注解
- hibernate注解onetomany manytoone
- Hibernate中ManyToOne,OneToMany,OneToOne的使用例
- 关于ManyToOne、ManyToMany、OneToOne所对应的表
- 关于jpa、hibernate的级联关系及注解OneToOne等注解解释
- Hibernate OneToOne注解关联查询案例
- org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.jpa.entity.Person.idCard refere
- org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.demo.pojo.IdCard
- Hibernate OneToOne
- hibernate--OneToOne
- 20、Linux 目录结构
- NYOJ 39 水仙花数
- Javascript 删除数组的指定元素
- 向表中插入一个字段
- Servelet 如何访问数据库
- 关于hibernate 注解 OnetoOne 或 ManyToOne 写法
- TextView 控件设置以及动态给布局添加控件
- C#线程等待句柄
- 哈希表及处理冲突的方法
- springMVC学习笔记-环境配置
- 8天学通MongoDB——第八天 驱动实践
- SQL 知识点
- 《C语言及程序设计》实践项目——枚举应用
- 介绍个比较简单的word转pdf方法