gpt4 book ai didi

java - JPA 或 Hibernate - 在不同类型的列上连接表

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:53:13 24 4
gpt4 key购买 nike

有没有办法告诉 Hibernate 在使用 to_char 连接到另一个表或相反地将 NUMBER 转换为 VARCHAR 时将列包装在 to_char 中?我有一种情况,我有一个表,其中包含一个类型为 VARCHAR 的通用键列,该列存储另一个表的 ID,该表是一个数字。当 Hibernate 执行它生成的使用“=”比较两列的 SQL 时,我收到了一个 SQL 异常。

谢谢...

附言我知道这并不理想,但我坚持使用模式,所以我必须处理它。

最佳答案

这应该可以在您的多对一中使用公式。来自 5.1.22. Column and formula elements 部分(此 previous answer 中也提到了解决方案):

column and formula attributes can even be combined within the same property or association mapping to express, for example, exotic join conditions.

<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;

关于java - JPA 或 Hibernate - 在不同类型的列上连接表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3096985/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com