我的应用程序中有以下对象模型和存储库:
@Entity
class Vehicle {}
class Car extends Vehicle {}
class Truck extends Vehicle {}
@Repository
public interface VehicleRepository extends JpaRepository<Vehicle, Long> {}
我试图开始工作的是:
Vehicle t = new Truck();
VehicleRepository r = new VehicleRepository();
r.save(t);
如何在不需要将Truck复制到Vehicle对象的情况下使此代码正常工作?
谢谢!
答案 0 :(得分:0)
Alan Hay与您联系,您需要设置继承:
其余的我重新链接Alan Hay提供的链接:https://en.wikibooks.org/wiki/Java_Persistence/Inheritance