@AttributeOverride 是什么意思?

2022-01-13 00:00:00 attributes overriding java jpa

我目前正在(回来)加快使用 EJB 的速度,而当我离开时,它发生了巨大的变化(到目前为止更好).但是,我遇到了一个我正在努力解决的概念,并且希望更好地理解它,因为它似乎在我们(我工作的地方,而不是我和我脑海中的所有声音)的代码中使用了很多.

I'm currently coming (back) up to speed with EJB and while I was away it changed drastically (so far for the better). However, I've come across a concept that I am struggling with and would like to understand better as it seems to be used in our (where I work, not me and all the voices in my head) code quite a bit.

这是我在一本书中找到的示例.它是展示如何使用 @EmbeddedId 注释的示例的一部分:

Here's the example I've found in a book. It's part of an example showing how to use the @EmbeddedId annotation:

@Entity
public class Employee implements java.io.Serializable
{
    @EmbeddedId
    @AttributeOverrides({
        @AttributeOverride(name="lastName", column=@Column(name="LAST_NAME"),
        @AttributeOverride(name="ssn", column=@Column(name="SSN"))
    })

    private EmbeddedEmployeePK pk;

    ...
}

EmbeddedEmployeePK 类是一个相当简单的 @Embeddable 类,它定义了一对 @Columns:lastNamessn.

The EmbeddedEmployeePK class is a fairly straightforward @Embeddable class that defines a pair of @Columns: lastName and ssn.

哦,我从 Rubinger & 的 O'Reilly 的 Enterprise JavaBeans 3.1 中提取了这个示例.伯克.

Oh, and I lifted this example from O'Reilly's Enterprise JavaBeans 3.1 by Rubinger & Burke.

提前感谢您能给我的任何帮助.

Thanks in advance for any help you can give me.

推荐答案

也就是说,构成嵌入 id 的属性可能已经预定义(通过显式或隐式映射)列名.通过使用 @AttributeOverride,您的意思是忽略关于它存储在哪一列的其他信息,并使用我在此处指定的信息".

It's saying that the attributes that make up the embedded id may have predefined (through explicit or implicit mappings) column names. By using the @AttributeOverride you're saying "ignore what other information you have with regard to what column it is stored in, and use the one I specify here".

相关文章