文档章节

@Inheritance

不正经茂
 不正经茂
发布于 2017/06/14 12:16
字数 182
阅读 11
收藏 0

SINGLE_TABLE

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Data
public class Biology {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String origin;
}
@Entity
@Data
public class Animal extends Biology{
    private Integer foot;
    private Integer wings;
}
@Entity
@Data
public class Plant extends Biology{
    private String leafShape;
}

生成的数据库中有一列dtype来标示是哪张表的数据:

CREATE TABLE IF NOT EXISTS biology (
  id BIGINT AUTO_INCREMENT PRIMARY KEY,
  dtype VARCHAR(255),
  origin VARCHAR(128),
  leaf_shape VARCHAR(128),
  foot INTEGER,
  wings INTEGER
);

JOINED

CREATE TABLE IF NOT EXISTS biology (
  id BIGINT AUTO_INCREMENT PRIMARY KEY,
  origin VARCHAR(128)
);

CREATE TABLE IF NOT EXISTS animal (
  id BIGINT AUTO_INCREMENT PRIMARY KEY,
  foot INTEGER,
  wings INTEGER
);

CREATE TABLE IF NOT EXISTS plant (
  id BIGINT AUTO_INCREMENT PRIMARY KEY,
  leaf_shape VARCHAR(128)
);

TABLE_PER_CLASS

CREATE TABLE IF NOT EXISTS biology (
  id BIGINT AUTO_INCREMENT PRIMARY KEY,
  origin VARCHAR(128)
);

CREATE TABLE IF NOT EXISTS animal (
  id BIGINT AUTO_INCREMENT PRIMARY KEY,
  origin VARCHAR(128),
  foot INTEGER,
  wings INTEGER
);

CREATE TABLE IF NOT EXISTS plant (
  id BIGINT AUTO_INCREMENT PRIMARY KEY,
  origin VARCHAR(128),
  leaf_shape VARCHAR(128)
);

© 著作权归作者所有

共有 人打赏支持
上一篇: 遍历map
不正经茂
粉丝 3
博文 40
码字总数 5071
作品 0
浦东
程序员
私信 提问
Inheritance versus composition

One of the fundamental activities of an object-oriented design is establishing relationships between classes. Two fundamental ways to relate classes are inheritance and composit......

Jerikc
2014/08/30
0
0
Extending entities in Symfony2 with Doctrine2

down vote You can see in this link to know about inheritance: http://docs.doctrine-project.org/en/latest/reference/inheritance-mapping.html#single-table-inheritance You must dec......

jims
2016/10/24
2
0
Inheritance vs. Composition in Java

This article illustrates the concepts of inheritance vs. composition in Java. It first shows an example of inheritance, and then shows how to improve the inheritance design by u......

Jerikc
2014/09/01
0
0
js中的prototype和构造函数

js中没有类的感念,继承也是通过原型链来实现的对象的继承而不是类的继承 Vjeux写的这篇文章应该能帮助我们更好的理解js中原型的工作方式:http://blog.vjeux.com/2011/javascript/how-proto...

leo-H
2013/04/08
0
0
Table Inheritance with Doctrine

NTRODUCTION Lately we had several projects where we had to store in a database very different items that shared a common state. As an example take the RocketLab website you are ......

jims
2016/11/14
3
0

没有更多内容

加载失败,请刷新页面

加载更多

java框架学习日志-13(Mybatis基本概念和简单的例子)

在mybatis初次学习Mybatis的时候,遇到了很多问题,虽然阿里云的视频有教学,但是视频教学所使用的软件和我自己使用的软件不用,我自己用的数据库是oracle数据库,开发环境是idea。而且视频中...

白话
今天
4
0
Java基础:String、StringBuffer和StringBuilder的区别

1 String String:字符串常量,字符串长度不可变。Java中String是immutable(不可变)的。 String类的包含如下定义: /** The value is used for character storage. */private final cha...

watermelon11
今天
2
0
mogodb服务

部署MongoDB 官网: https://www.mongodb.com/download-center/community 创建mongo数据目录 mkdir /data/mongodb 二进制部署 wget -c https://fastdl.mongodb.org/linux/mongodb-linux-x8......

以谁为师
昨天
5
0
大神教你Debian GNU/Linux 9.7 “Stretch” Live和安装镜像开放下载

Debian项目团队于昨天发布了Debian GNU/Linux 9 "Stretch" 的第7个维护版本更新,重点修复了APT软件管理器中存在的安全漏洞。在敦促每位用户尽快升级系统的同时,Debian团队还发布了Debian ...

linux-tao
昨天
4
0
PHP 相关配置

1. php-fpm的pool 编辑php-fpm配置文件php-fpm.con vim /usr/local/php/etc/php-fpm.conf //在[global]部分增加以下内容 include = etc/php-fpm.d/*.conf # 相当与Nginx的虚拟主机文件 “vho......

Yue_Chen
昨天
2
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部