我正在用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工作正常!所以我回到了不理解的状态......
任何人都知道如何在层次结构中使用可嵌入的实体?那甚至是问题?
糟糕,我的坏...还是一个关于这些技术的新手:(无论如何非常感谢你Mikko! – Thomas