[英]JPA or Hibernate - Joining tables on columns of different types
有沒有辦法告訴Hibernate在使用它連接到另一個表或反過來將NUMBER轉換為VARCHAR時將其包裝在to_char中? 我有一種情況,我有一個表,其中包含VARCHAR類型的通用鍵列,它存儲另一個表的ID,它是一個數字。 當Hibernate執行它生成的SQL時,我得到一個SQL異常,它使用'='來比較兩列。
謝謝...
PS我知道這不太理想,但我堅持使用架構,所以我必須處理它。
這應該可以使用多對一的公式。 來自第5.1.22節。 列和公式元素 ( 前一個答案中也提到了解決方案):
column
和formula
屬性甚至可以在同一屬性或關聯映射中組合,以表示例如異國連接條件。<many-to-one name="homeAddress" class="Address" insert="false" update="false"> <column name="person_id" not-null="true" length="10"/> <formula>'MAILING'</formula> </many-to-one>
使用注釋(如果您使用的是Hibernate 3.5.0-Beta-2 +,請參閱HHH-4382 ):
@ManyToOne
@Formula(value="( select v_pipe_offerprice.offerprice_fk from v_pipe_offerprice where v_pipe_offerprice.id = id )")
public OfferPrice getOfferPrice() { return offerPrice; }
或者也許查看@JoinColumnsOrFormula
:
@ManyToOne
@JoinColumnsOrFormulas(
{ @JoinColumnOrFormula(formula=@JoinFormula(value="SUBSTR(product_idnf, 1, 3)", referencedColumnName="product_idnf")) })
@Fetch(FetchMode.JOIN)
private Product productFamily;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.