簡體   English   中英

在Hibernate中擴展具有某些關系的表

[英]Extending a table in Hibernate which has some relations

我有一個實體,想通過添加一些字段來擴展它。 首先,我無法直接更改它們,它們在自己的jar文件中。 這是基本實體:

@Entity
table(name="ACCOUNTDEF")
public class EtAccountDef

{
private String cNumber;
private List<EtAccount> accounts = new ArrayList();

public String getCNumber()
{
  return cNumber;
}

public void setCNumber(String cNumber) {
  this.cNumber = cNumber;
}

@OneToMany(fetch=FetchType.LAZY, cascade={javax.persistence.CascadeType.ALL}, mappedBy="accountDef")
public List<EtAccount> getAccounts() {
  return accounts;
}

public void setAccounts(List<EtAccount> accounts) {
  this.accounts = accounts;
}
}

這是父類,下面是子類:

 @Entity
 @Table(name="ACCOUNT")
 public class EtAccount
 {
   private Double accountAmount;
   private EtAccountDef accountDef;
   private List<EtAccountItems> accountItems = new ArrayList();

    @ManyToOne(fetch=FetchType.LAZY)
   public EtAccountDef getAccountDef() {
     return accountDef;
   }

   public void setAccountDef(EtAccountDef accountDef) {
     this.accountDef = accountDef;
   }

   @OneToMany(fetch=FetchType.LAZY, cascade={javax.persistence.CascadeType.ALL}, mappedBy="account")
   public List<EtAccountItems> getAccountItems() {
     return accountItems;
   }

   public void setAccountItems(List<EtAccountItems> accountItems) {
     this.accountItems = accountItems;
   }
 }

因此我嘗試了這些更改以實現自己的目標。

@MappedSuperclass
public abstract class OtAbstractAccount extends EtAccount {
    private Double AccountCommission;

    @Column(columnDefinition="decimal(15,2)")
    public Double getAccountCommission() {
        return accountCommission;
    }
    public void setAccountCommission(Double accountCommission) {
        this.accountCommission = accountCommission;
    }

然后通過此實體對其進行擴展:

@Entity
@Table(name="ACCOUNT")
public class OtCostumAccount extends OtAbstractAccount {
}

現在,這些字段已添加到基本表(EtAccount)中,但是在編譯后,我在Weblogic中收到一條錯誤消息,內容為:

由以下原因引起:org.hibernate.AnnotationException:EtAccount.accountDef上的@OneToOne或@ManyToOne引用了一個未知實體:EtAccountDef

我在ORM文件中輸入了以下兩行:

 <mapped-superclass class="package.OtAbstractAccount" /> 
 <entity class="package.OtCostumAccount" />

令人驚訝的是當我評論

 <mapped-superclass class="package.OtAbstractAccount" /> 

從ORM的weblogic不會出現任何錯誤,但是當我嘗試加載對象時,將創建另一個錯誤,說:

引起原因:javax.persistence.PersistenceException:org.hibernate.exception.SQLGrammarException:ORA-00904:“ OtCostumAccount”。“ DTYPE”:無效的標識符

我對這些錯誤感到困惑,不勝感激。

如果無法修改父類,則適用默認的休眠繼承策略:每個類一個表。 此策略需要一個區分列,默認情況下為DTYPE。 您是否嘗試將鑒別符列添加到OtCostumAccount實體或創建DTYPE列?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM