在继承状态层次结构中找不到声明类:UserAccount

时间:2017-04-18 09:05:15

标签: java hibernate jpa servlets

我正在使用带有JPA + Hibernate的servlet)。除非我尝试过本论坛中提出的其他解决方案,否则我不明白错误。实际上,我不想将UserAccount类存储为实体;但我只是想在Utilisateur类中声明它(Utilisateur类的Ids在useraccount类中声明)。

我的代码:

@Entity
@Table(name = "utilisateur")
public class Utilisateur implements Serializable {

    @Id
    private UserAccount userAccount;

    private Civility civility;

    private Address address;

    private Contact contact;

    @Column(name = "sessions")
    private List<String> sessions;

    @Column(name = "particularRules")
    private boolean particularRules;

    public Utilisateur(UserAccount pAccount, Civility pCivility, 
        Address pAddress, Contact pContact, List<String> 
        pSessions, 
        boolean particularRules) {
        this.userAccount = pAccount;
        this.civility = pCivility;
        this.address = pAddress;
        this.contact = pContact;
        this.sessions = pSessions;
        this.particularRules = particularRules;
    }

    public Civility getCivility() {
        return civility;
    }

    public void setCivility(Civility civility) {
        this.civility = civility;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public Contact getContact() {
        return contact;
    }

    public void setContact(Contact contact) {
        this.contact = contact;
    }

    public boolean isParticularRules() {
        return particularRules;
    }

    public void setParticularRules(boolean particularRules) {
        this.particularRules = particularRules;
    }

    public UserAccount getUserAccount() {
        return userAccount;
    }

    public void setUserAccount(UserAccount userAccount) {
        this.userAccount = userAccount;
    }

    public List<String> getSessions() {
        return sessions;
    }

    public void setSessions(List<String> sessions) {
        this.sessions = sessions;
    }
}

@Embeddable
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class UserAccount implements Serializable {
public UserAccount() {

}

public UserAccount(String pId, String pEmail, String pwsd, Date pCreaDate, Date pLastModDate) {
    this.identifier = pId;
    this.email = pEmail;
    this.password = pwsd;
    this.creationDate = pCreaDate;
    this.lastModificationDate = pLastModDate;
}

@OneToOne(mappedBy = "userAccount", cascade = CascadeType.ALL, 
fetch = FetchType.EAGER, orphanRemoval = true, targetEntity = 
Utilisateur.class)
private Utilisateur user;

@Column(name = "creationDate")
@Temporal(javax.persistence.TemporalType.DATE)
private Date creationDate;

@Column(name = "lastModificationDate")
@Temporal(javax.persistence.TemporalType.DATE)
private Date lastModificationDate;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "identifier", nullable = false)
private String identifier;

@Column(name = "email")
private String email;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "password", nullable = false)
private String password;

public String getIdentifier() {
    return identifier;
}

public void setIdentifier(String identifier) {
    this.identifier = identifier;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public Date getCreationDate() {
    return creationDate;
}

public void setCreationDate(Date creationDate) {
    this.creationDate = creationDate;
}

public Date getLastModificationDate() {
    return lastModificationDate;
}

public void setLastModificationDate(Date lastModificationDate) {
    this.lastModificationDate = lastModificationDate;
}

public Utilisateur getUser() {
    return user;
}

public void setUser(Utilisateur user) {
    this.user = user;
}

}

2 个答案:

答案 0 :(得分:3)

您必须使用 嵌入式主键

在Stackoverflow How to create and handle composite primary key in JPA中查看此问题的答案。

祝你好运!

答案 1 :(得分:0)

嵌入式主键包含@EmbeddedId时可能会发生这种情况。子复合键应该用@Embedded注释。