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???
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With