English 中文(简体)
是否有办法推翻继承的世代战略?
原标题:Is there a way to override inherited generation strategy?

I m 扩展一个拥有汽车的实体。

我想在我的产阶级中将其世代战略压倒给非统组织。

与此类似。

@Entity
public class Base {

    @Id
    @Column(name = "id")
    public Integer getId() {
      return id;
    }

}

@Entity
public class Extender extends Base {

    @GeneratedValue(strategy = GenerationType.AUTO)
    public Integer getId() {
        return super.getId();
    }
}

这是我努力做到的:

Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: Extender column: id (should be mapped with insert="false" update="false")

我理解为什么会发生这种情况,但我需要知道,这样做是否有效。

感谢

最佳回答

不可能做到这一点,因为只有一度才能界定主要关键,而根特多尔韦洛是界定主要关键因素。 与具体措辞相同:

2.4 Primary Keys and Entity Identity
... The primary key must be defined exactly once in an entity hierarchy.

11.1.17 GeneratedValue Annotation
... The GeneratedValue annotation may be applied to a primary key property or field of an entity or mapped superclass in conjunction with the Id annotation.

问题回答

这并不正确。 如果你想要继承遗产,你要么必须继承。

  • specify @javax.persistence.Inheritance in the base class and choose a strategy how the inheritance is to be mapped (enum InheritanceType)
  • annotate the class Base with @javax.persistence.MappedSuperclass

此外,还研究了通知@javax.persistence. Transient,其中允许你在超级舱或超级接口中确定财产,而不必具体指明该地的地图。

在数据模型中,我根本不喜欢继承,因为开发商往往使用<>条码/代码>操作器,如果你没有实体类别的实际事例,而是出于自愿的代理物体(如果是电齐装载的话),则在操作时间会产生意外结果。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签