0

環境: JDK 1.6、JEE5 Hibernate Core 3.3.1.GA、Hibernate Annotations 3.4.0.GA DB: Informix

リバース エンジニアリングを使用して、db スキーマから永続化エンティティを作成しました [注: これは作業中のスキーマであり、変更できません]

basic_auth_accounts org.hibernate.TypeMismatchException のリストを選択すると例外が発生する: クラス ebusiness.weblogic.model.UserAccounts に間違ったタイプの ID が提供されました。予想: クラス ebusiness.weblogic.model.UserAccountsId、クラス ebusiness.weblogic.model.BasicAuthAccountsId を取得

basic_auth_accounts と user_accounts の両方に複合主キーと 1 対 1 の関係があります。ここで何をすべきか手がかりはありますか?これは、私がこれを機能させるために非常に重要です。ネット上で実質的な解決策を見つけることができず、hibernate が行った ID クラスを作成すると言う人もいれば、1 対 1 の関係を持たないと言う人もいます。

私を助けてください!!

/**
* BasicAuthAccounts generated by hbm2java
*/
@Entity
@Table(name = "basic_auth_accounts", schema = "ebusdevt", catalog = "ebusiness_dev", uniqueConstraints = @UniqueConstraint(columnNames = {
        "realm_type_id", "realm_qualifier", "account_name" }))
public class BasicAuthAccounts implements java.io.Serializable {

    private BasicAuthAccountsId id;
    private UserAccounts userAccounts;
    private String accountName;
    private String hashedPassword;
    private boolean passwdChangeReqd;
    private String hashMethodId;
    private int failedAttemptNo;
    private Date failedAttemptDate;
    private Date lastAccess;

    public BasicAuthAccounts() {
    }

    public BasicAuthAccounts(UserAccounts userAccounts, String accountName, String hashedPassword,
            boolean passwdChangeReqd, String hashMethodId, int failedAttemptNo) {
        this.userAccounts = userAccounts;
        this.accountName = accountName;
        this.hashedPassword = hashedPassword;
        this.passwdChangeReqd = passwdChangeReqd;
        this.hashMethodId = hashMethodId;
        this.failedAttemptNo = failedAttemptNo;
    }

    public BasicAuthAccounts(UserAccounts userAccounts, String accountName, String hashedPassword,
            boolean passwdChangeReqd, String hashMethodId, int failedAttemptNo,
            Date failedAttemptDate, Date lastAccess) {
        this.userAccounts = userAccounts;
        this.accountName = accountName;
        this.hashedPassword = hashedPassword;
        this.passwdChangeReqd = passwdChangeReqd;
        this.hashMethodId = hashMethodId;
        this.failedAttemptNo = failedAttemptNo;
        this.failedAttemptDate = failedAttemptDate;
        this.lastAccess = lastAccess;
    }

    @EmbeddedId
    @AttributeOverrides( {
            @AttributeOverride(name = "realmTypeId", column = @Column(name = "realm_type_id", nullable = false, length = 32)),
            @AttributeOverride(name = "realmQualifier", column = @Column(name = "realm_qualifier", nullable = false, length = 32)),
            @AttributeOverride(name = "accountId", column = @Column(name = "account_id", nullable = false)) })
    public BasicAuthAccountsId getId() {
        return this.id;
    }

    public void setId(BasicAuthAccountsId id) {
        this.id = id;
    }

    @OneToOne(fetch = FetchType.LAZY)
    @PrimaryKeyJoinColumn
    @NotNull
    public UserAccounts getUserAccounts() {
        return this.userAccounts;
    }

    public void setUserAccounts(UserAccounts userAccounts) {
        this.userAccounts = userAccounts;
    }

/**
* BasicAuthAccountsId generated by hbm2java
*/
@Embeddable
public class BasicAuthAccountsId implements java.io.Serializable {

    private String realmTypeId;
    private String realmQualifier;
    private long accountId;

    public BasicAuthAccountsId() {
    }

    public BasicAuthAccountsId(String realmTypeId, String realmQualifier, long accountId) {
        this.realmTypeId = realmTypeId;
        this.realmQualifier = realmQualifier;
        this.accountId = accountId;
    }

/**
* UserAccounts generated by hbm2java
*/
@Entity
@Table(name = "user_accounts", schema = "ebusdevt", catalog = "ebusiness_dev")
public class UserAccounts implements java.io.Serializable {

    private UserAccountsId id;
    private Realms realms;
    private UserDetails userDetails;
    private Integer accessLevel;
    private String status;
    private boolean isEdge;
    private String role;
    private boolean chargesAccess;
    private Date createdTimestamp;
    private Date lastStatusChangeTimestamp;
    private BasicAuthAccounts basicAuthAccounts;
    private Set<Sessions> sessionses = new HashSet<Sessions>(0);
    private Set<AccountGroups> accountGroupses = new HashSet<AccountGroups>(0);
    private Set<UserPrivileges> userPrivilegeses = new HashSet<UserPrivileges>(0);

    public UserAccounts() {
    }

    public UserAccounts(UserAccountsId id, Realms realms, UserDetails userDetails, String status,
            boolean isEdge, boolean chargesAccess) {
        this.id = id;
        this.realms = realms;
        this.userDetails = userDetails;
        this.status = status;
        this.isEdge = isEdge;
        this.chargesAccess = chargesAccess;
    }


    @EmbeddedId
    @AttributeOverrides( {
            @AttributeOverride(name = "realmTypeId", column = @Column(name = "realm_type_id", nullable = false, length = 32)),
            @AttributeOverride(name = "realmQualifier", column = @Column(name = "realm_qualifier", nullable = false, length = 32)),
            @AttributeOverride(name = "accountId", column = @Column(name = "account_id", nullable = false)) })
    @NotNull
    public UserAccountsId getId() {
        return this.id;
    }

    public void setId(UserAccountsId id) {
        this.id = id;
    }



    @OneToOne(fetch = FetchType.LAZY, mappedBy = "userAccounts")
    public BasicAuthAccounts getBasicAuthAccounts() {
        return this.basicAuthAccounts;
    }

    public void setBasicAuthAccounts(BasicAuthAccounts basicAuthAccounts) {
        this.basicAuthAccounts = basicAuthAccounts;
    }

/**
* UserAccountsId generated by hbm2java
*/
@Embeddable
public class UserAccountsId implements java.io.Serializable {

    private String realmTypeId;
    private String realmQualifier;
    private long accountId;

    public UserAccountsId() {
    }

    public UserAccountsId(String realmTypeId, String realmQualifier, long accountId) {
        this.realmTypeId = realmTypeId;
        this.realmQualifier = realmQualifier;
        this.accountId = accountId;
    }

    @Column(name = "realm_type_id", nullable = false, length = 32)
    @NotNull
    @Length(max = 32)
    public String getRealmTypeId() {
        return this.realmTypeId;
    }

    public void setRealmTypeId(String realmTypeId) {
        this.realmTypeId = realmTypeId;
    }

    @Column(name = "realm_qualifier", nullable = false, length = 32)
    @NotNull
    @Length(max = 32)
    public String getRealmQualifier() {
        return this.realmQualifier;
    }

    public void setRealmQualifier(String realmQualifier) {
        this.realmQualifier = realmQualifier;
    }

    @Column(name = "account_id", nullable = false)
    public long getAccountId() {
        return this.accountId;
    }

    public void setAccountId(long accountId) {
        this.accountId = accountId;
    }

クラスのメイン コードは次のとおりです。

4

1 に答える 1

0

オンラインでの検索/調査をフォローアップするためだけに:

私が見ることができるものから、同じ複合キーrealmTypeId、realmQualifier、およびaccountIdを使用する2つのテーブルbasic_auth_accountsとuser_accountsがあります。両方のエンティティには、これらの列と1対1の関係を持つ埋め込み可能なクラスがあります。

休止状態のツールを使用して、変更できないDBスキーマからこれらのエンティティを生成しました。

BasicAuthAccountsIdの名前をより一般的な名前に変更する場合のように、両方のエンティティに同じ埋め込み可能クラスを使用したかどうか疑問に思っています。UserAccountsIdを削除し、両方のエンティティに同じ@EmbeddedIdクラスを使用しますか?

于 2010-05-19T04:48:00.043 に答える