2011-12-02 47 views
3

我正在用EJB3开发用户/密码系统。EJB3中的嵌入式对象继承

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

这里有 “签名”:

@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)]) 

第2部分:

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)]) 

因此,我从这些例外中了解到,GeneratedPassword不被识别为实体。但是如果我使用密码类,evrything工作正常!所以我回到了不理解的状态......

任何人都知道如何在层次结构中使用可嵌入的实体?那甚至是问题?

回答

2

规范不会说明任何有关嵌入继承的内容,因此看起来像不支持。可能因为简单为目标。

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

顺便说一句,问题被打上休眠,但您使用的EclipseLink。

+0

糟糕,我的坏...还是一个关于这些技术的新手:(无论如何非常感谢你Mikko! – Thomas