- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 3 节课:
@MappedSuperclass
public class BaseEntity {
@Id
@GeneratedValue
private Long id;
...
}
@Entity
public class Person extends BaseEntity {
private String name;
...
}
@Entity
@AttributeOverride(name = "id", @Column = (name = "idStudent"))
public class Student extends Person {
private float avgGrades;
...
}
我想覆盖 ID 属性,以便在 Student 表中会有一个 idStudent
列,而不是 id
。不幸的是,上面的代码不起作用。看起来 @AttributeOverride 只适用于您扩展的类(并且没有进一步的一步)。在我描述的情况下有什么方法可以覆盖属性名称(覆盖类中扩展我们正在扩展的类的属性)吗?
最佳答案
如果您知道默认继承类型是什么:SINGLE_TABLE
,那么您的问题很容易理解。
这意味着扩展 Person
的所有实体都在同一个表中。因此 Person
已经定义了 ID 列。因为否则您将违反 Person
表的主键列的约定。
我还引用了@AttributeOverride
的JavaDoc:
May be applied to an entity that extends a mapped superclass or to an embedded field or property to override a basic mapping or id mapping defined by the mapped superclass or embeddable class (or embeddable class of one of its attributes).
在此处提问之前,先阅读 JavaDoc 总是有帮助的。
你能做些什么呢?让您的 Person
成为 @MappedSuperclass
(或创建一个 BasePerson
)。
关于java - Hibernate 和 @AttributeOverride,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31865191/
我试图更改子类表中的列名,但 @AttributeOverride 注释并未更改它。 @Entity @Table(name="emp") @Inheritance(strategy=Inherita
我有代码 @MappedSuperclass @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @XmlAccessorType(Xml
您好,我遇到了 Hibernate 和 @AttributeOverrides 注释的问题。 我有可嵌入的类(class)钱 @Embeddable public class Money imple
嵌入式 Money 类中有面额字段。 @Column(scale = 4, precision = 20) private BigDecimal denomination; 当我在某些实体类中多次使用
我有课 @Embeddable public class MyClass implements Serializable { private String field1; private
我目前正在(回来)加快使用 EJB 的速度,而当我离开时,它发生了巨大的变化(到目前为止更好)。但是,我遇到了一个我正在努力解决的概念,并且希望更好地理解它,因为它似乎在我们(我工作的地方,而不是我和
我有一个我需要手动设置 ID (PK) 的实体。 我有一些抽象的 @MappedSuperclass 用于审计和 PK,我仍然想使用它。所以我的想法是覆盖 id 列以摆脱 @GeneratedValu
我有 3 节课: @MappedSuperclass public class BaseEntity { @Id @GeneratedValue private Long id
设置:Hibernate 4.0 (JPA 2.0)、Java EE 6 我有以下问题:我有一个用 @Embeddable 注释的“HandAttributes”类,它包含很多 boolean 属性。
我有一个子类,它覆盖其父类(super class)的 getter(因为它添加了不同的行为)。我正在使用@AttributeOverride,但它也会引发错误org.hibernate.Mappin
谁能帮我设置正确的方法来覆盖扩展实体中的列名。 可嵌入: @Embedable Email @Column(name = "email_adress") private string email; 父
我有嵌入两个 ModelId 类的实体,其中一个是 EmbeddedId ,另一个引用另一个实体。 @Entity public class Report implements Serializabl
我有以下实体: public class MyEntity extends AuditableEntity { @Column private String name; } Audit
我有类 Money 这是一个@Embeddable @Embeddable public class Money implements Serializable, Comparable { @
我有 2 个 SQL 表: 用户: CREATE TABLE users ( id BIGINT PRIMARY KEY DEFAULT nextval('global_seq'),
我有一个名为 BaseTable 的 MapperSuperclass: @MappedSuperclass public abstract class BaseTable { @Column
除此之外,如果这样做是正确的模式,那么问题是在 Hibernate 中是否可以为给定的 @MappedSuperclass 将覆盖属性设置为 @Transient 或以任何“其他方式”忽略它? 给定的
来 self 的实体角色的代码 @Embedded @LazyCollection(LazyCollectionOption.FALSE) @CollectionOfElements
我使用的是 Hibernate 5.2.6 版。我有一个实例,我必须使用 @AttributeOverrides 注释来覆盖我之前与另一个实体一起使用的嵌入式列属性的名称。但它似乎没有用。 我得到了
@Entity class User { @EmbeddedId @AttributeOverride(name="firstName", column=@Column(name="fld_first
我是一名优秀的程序员,十分优秀!