JPA中的@MappedSuperclass
说明地址:http://docs.oracle.com/javaee/5/api/javax/persistence/MappedSuperclass.html
用来申明一个超类,继承这个类的子类映射时要映射此类中的字段,可以当做是对entity抽取封装的类。如果子类想重写此类的映射信息,可以使用 AttributeOverride
and AssociationOverride
annotations
- Example: Concrete class as a mapped superclass
- @MappedSuperclass
- public class Employee {
- @Id
- protected Integer empId;
- @Version
- protected Integer version;
- @ManyToOne @JoinColumn(name="ADDR")
- protected Address address;
- public Integer getEmpId() { ... }
- public void setEmpId(Integer id) { ... }
- public Address getAddress() { ... }
- public void setAddress(Address addr) { ... }
- }
- // Default table is FTEMPLOYEE table
- @Entity
- public class FTEmployee extends Employee {
- // Inherited empId field mapped to FTEMPLOYEE.EMPID
- // Inherited version field mapped to FTEMPLOYEE.VERSION
- // Inherited address field mapped to FTEMPLOYEE.ADDR fk
- // Defaults to FTEMPLOYEE.SALARY
- protected Integer salary;
- public FTEmployee() {}
- public Integer getSalary() { ... }
- public void setSalary(Integer salary) { ... }
- }
- @Entity @Table(name="PT_EMP")
- @AssociationOverride(name="address",
- joincolumns=@JoinColumn(name="ADDR_ID"))
- public class PartTimeEmployee extends Employee {
- // Inherited empId field mapped to PT_EMP.EMPID
- // Inherited version field mapped to PT_EMP.VERSION
- // address field mapping overridden to PT_EMP.ADDR_ID fk
- @Column(name="WAGE")
- protected Float hourlyWage;
- public PartTimeEmployee() {}
- public Float getHourlyWage() { ... }
- public void setHourlyWage(Float wage) { ... }
- }
- Example: Non-entity superclass
- public class Cart {
- // This state is transient
- Integer operationCount;
- public Cart() { operationCount = 0; }
- public Integer getOperationCount() { return operationCount; }
- public void incrementOperationCount() { operationCount++; }
- }
- @Entity
- public class ShoppingCart extends Cart {
- Collection items = new Vector();
- public ShoppingCart() { super(); }
- ...
- @OneToMany
- public Collection getItems() { return items; }
- public void addItem(Item item) {
- items.add(item);
- incrementOperationCount();
- }
- }
转载于:https://www.cnblogs.com/toSeeMyDream/p/4606896.html
JPA中的@MappedSuperclass相关推荐
- java实体外键_如何在JPA中添加用户实体和好友关系实体的外键
现有用户实体,相关代码如下: @Entity @Table(name = "t_users") public class User extends Model { @Id @Col ...
- jpa中使用Query判断条件查询
jpa中使用Query判断条件查询 @Query(value = " select m.* from mining_area as m " +" where 1 = 1& ...
- 解决Springboot+JPA中多表关联查询会查询多次的问题(n+1查询问题)
解决Springboot+JPA中多表关联查询会查询多次的问题(n+1查询问题) 参考文章: (1)解决Springboot+JPA中多表关联查询会查询多次的问题(n+1查询问题) (2)https: ...
- JPA中实现双向多对多的关联关系(附代码下载)
场景 JPA入门简介与搭建HelloWorld(附代码下载): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103473937 ...
- JPA中实现双向一对一的关联关系
场景 JPA入门简介与搭建HelloWorld(附代码下载): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103473937 ...
- JPA中实现双向一对多的关联关系
场景 JPA入门简介与搭建HelloWorld(附代码下载): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103473937 ...
- JPA中实现单向一对多的关联关系
场景 JPA入门简介与搭建HelloWorld(附代码下载): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103473937 ...
- Spring Boot JPA 中transaction的使用
文章目录 @Transactional的实现 @Transactional的使用 Transaction的传播级别 REQUIRED SUPPORTS MANDATORY NEVER NOT_SUPP ...
- Spring Boot JPA中关联表的使用
文章目录 添加依赖 构建Entity 构建Repository 构建初始数据 测试 Spring Boot JPA中关联表的使用 本文中,我们会将会通过一个Book和Category的关联关系,来讲解 ...
最新文章
- idea中一个maven项目增加Web支持
- 149. Leetcode 1005. K 次取反后最大化的数组和 (贪心算法-基础题目)
- hadoop_namenode如果选择在哪个datanode存储副本
- 还贷的那些事I——还贷的基本概念
- vue与php接口对接,怎样使用vue项目中api接口
- linux之安装mysql提示Error: Unable to find a match: mysql-community-server
- python 实现点击右键用某个程序打开功能_工欲善其事,必先利其器(1)——Python开发环境安装与配置...
- 100亿估值的文和友,为何难以“走出”长沙?
- 20200922:leetcode35周双周赛题解记录(下)
- 安装 jupyter notebook
- python生成矢量图_Jupyter Notebook输出矢量图实例
- 21. 总是让比较函数在等值情况下返回false
- 推荐装机软件更新下载(2006.11.7更新)
- springboot中使用thymeleaf片段引入出现500错误(易错)
- Eason's concert
- 图集 | 航拍玉林29所学校,里面有你的母校吗?
- 【摸鱼神器】— 五子棋
- 李白关于鸿蒙的诗,李白6首山水古诗,首首美到让人心碎
- 【深入理解RabbitMQ原理】RabbitMQ 配置,生产者和消费者
- 2021.1.30课程摘要(逻辑教育-王劲胜)
热门文章
- Thinkphp 配置不用输入index.php
- zabbix4.0 使用nginx前端安装
- Codeforces Round #201 (Div. 2)C,E
- 12.18栈、队列练习题
- LintCode 两两交换链表中的节点
- 系统地学习JavaScript
- 基于Response的将数据导出到Excel
- linux火狐浏览器49.0安装教程,火狐浏览器Linux最新版下载
- Python爬虫自学之第(①)篇——爬虫伪装和反“反爬”
- 支付宝支付—沙箱环境使用