java - 使用 Spring Data JPA 映射多级继承的最佳方法是什么?
问题描述
我的项目中有这种类型的结构:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class Vehicle implements Serializable {}
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "ENGINE_TYPE", discriminatorType = DiscriminatorType.STRING)
public class Car extends Vehicle {}
@DiscriminatorValue("E")
@Entity
public class ElectricCar extends Car {}
@DiscriminatorValue("ICE")
@Entity
public class InternalCombustionEngineCar extends Car {}
@DiscriminatorValue("H")
@Entity
public class HybridcCar extends Car {}
Vehicle
类有@Inheritance(strategy = InheritanceType.JOINED)
并且我想@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
与类一起使用,Car
因为每个子类中只有 3 个子类具有 1 个属性。但问题是即使我SINGLE_TABLE
为类指定了策略Car
,它仍然为每个子类创建单独的表。有什么办法可以修复吗?还是有更优化的解决方案?
谢谢
解决方案
推荐阅读
- reactjs - Laravel 灯塔当前用户通过下一个阿波罗为空
- linux - cron 脚本未在 Raspberry Pi 上执行
- flutter - AndroidManifest 颤动中缺少默认通知通道元数据
- sql - 如何在 Linq Vb.net 中更改数据库名称
- c++ - 是否可以从 CLions 覆盖界面中排除目录到 gcov?
- swift - 如何创建运算符来实现错误链接?
- python - 将图像中的白色像素更改为不同的颜色
- xcode - 如何使用 SwiftUI 消除嵌套 NavigationView 中的空间
- python-3.x - 如何在 Django 模型中创建 VIEW 表的数据库?
- java - 如何将图像/文件上传到 Tomcat 服务器