EJB3 中的嵌入式对象继承

发布于 2024-12-19 08:14:07 字数 1805 浏览 1 评论 0原文

我正在使用 EJB3 开发用户/密码系统。

用户有一个嵌入的密码。 我有两种密码:用户定义的或非用户定义的。 因此,我有一个超类“密码”及其子类“生成密码”。建筑确实是有争议的。

以下是“签名”:

@Entity
@NamedQueries({ //... })
@Table(name="UserAccount")
public class UserAccount implements Serializable {

    @Id
    @Email
    private String email;

    @Embedded
    private Password password;


    public UserAccount(String email) {
        this.email = email;
        this.password = new  GeneratedPassword();
    }

    // ...
}

@Embeddable
public class Password implements Serializable {

    private String encryptedPassword;

    // ...
}

@Embeddable
public class GeneratedPassword extends Password {

    private String tmpPassword;
    // ...
}

问题是我遇到了一个奇怪的异常(很奇怪,因为我不理解它......):

Caused by: javax.persistence.EntityExistsException: 
Exception Description: No subclass matches this class [class entities.user.GeneratedPassword] for this Aggregate mapping with inheritance.
Mapping: org.eclipse.persistence.mappings.AggregateObjectMapping[password]
Descriptor: RelationalDescriptor(entities.user.UserAccount --> [DatabaseTable(UserAccount)])

第二部分:

Caused by: Exception [EclipseLink-126] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: No subclass matches this class [class entities.user.GeneratedPassword] for this Aggregate mapping with inheritance.
Mapping: org.eclipse.persistence.mappings.AggregateObjectMapping[password]
Descriptor: RelationalDescriptor(entities.user.UserAccount --> [DatabaseTable(UserAccount)])

所以我从这些异常中了解到的是,GeneratePassword 不被识别为实体。但如果我使用密码类,一切都工作正常!所以我又回到了不理解的状态...

有人知道如何在层次结构中使用可嵌入实体吗?这还有问题吗???

I am developping an user/password system with EJB3.

An user have an embedded password.
And I have two kinds of passwords: user defined or not.
Therefore I have a superclass Password, and its subclass GeneratedPassword. Architecture is indeed debatable.

Here are the "signatures" :

@Entity
@NamedQueries({ //... })
@Table(name="UserAccount")
public class UserAccount implements Serializable {

    @Id
    @Email
    private String email;

    @Embedded
    private Password password;


    public UserAccount(String email) {
        this.email = email;
        this.password = new  GeneratedPassword();
    }

    // ...
}

@Embeddable
public class Password implements Serializable {

    private String encryptedPassword;

    // ...
}

@Embeddable
public class GeneratedPassword extends Password {

    private String tmpPassword;
    // ...
}

Problem is I am having a weird exception (weird because I don't understand it...):

Caused by: javax.persistence.EntityExistsException: 
Exception Description: No subclass matches this class [class entities.user.GeneratedPassword] for this Aggregate mapping with inheritance.
Mapping: org.eclipse.persistence.mappings.AggregateObjectMapping[password]
Descriptor: RelationalDescriptor(entities.user.UserAccount --> [DatabaseTable(UserAccount)])

2nd part:

Caused by: Exception [EclipseLink-126] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: No subclass matches this class [class entities.user.GeneratedPassword] for this Aggregate mapping with inheritance.
Mapping: org.eclipse.persistence.mappings.AggregateObjectMapping[password]
Descriptor: RelationalDescriptor(entities.user.UserAccount --> [DatabaseTable(UserAccount)])

So what I understand from these exceptions is that the GeneratedPassword is not recognized as an entity. But if I use the Password class, evrything works fine! So I'm back to the incomprehension state...

Anybody knows how to use embeddable entities within a hierarchy? Is that even the problem???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疾风者 2024-12-26 08:14:07

规范没有告诉任何有关可嵌入项的继承的信息,因此看起来不支持它。可能是因为以简单为目标。

当然,某些实现可以拥有它。不幸的是 Hibernate 不是其中之一: https://hibernate.onjira.com/browse/HHH-1910
Eclipselink 支持,但不通过注释或 XML 描述符: http:// wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Entities/Embeddable#Inheritance

顺便说一下,问题是标记为 hibernate,但您使用 EclipseLink。

Specification does not tell anything about inheritance of embeddables, so looks like it is not supported. Probably because of simplicity as target.

Of course some implementations can have it. Unfortunately Hibernate is not one of those: https://hibernate.onjira.com/browse/HHH-1910
Eclipselink supports, but not via annotation or XML descriptor: http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Entities/Embeddable#Inheritance

By the way, question is tagged with hibernate, but you use EclipseLink.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文