gpt4 book ai didi

java - JPA @ManyToOne @JoinFormula 抛出 ClassCastException

转载 作者:行者123 更新时间:2023-12-02 12:03:38 27 4
gpt4 key购买 nike

我正在尝试使用 JPA 建立多对一双向关联模型。连接使用公式。我尝试了几种方法,如下所示。一次仅使用 JoinFormula,另一次使用 JoinColumnsOrFormulas。

public class JobOperation
{
private Operation operation;

@ManyToOne
// @JoinFormula("CASE WHEN attribute7 IS NULL OR TO_NUMBER(attribute7) = 0 THEN standard_operation_id ELSE TO_NUMBER(attribute7) END")
@JoinColumnsOrFormulas(
{
@JoinColumnOrFormula(formula = @JoinFormula(//
value = "(CASE WHEN this_.attribute7 IS NULL OR TO_NUMBER(this_.attribute7) = 0 THEN this_.standard_operation_id ELSE TO_NUMBER(this_.attribute7) END)", //
referencedColumnName = "standard_operation_id"))
})
@Fetch(FetchMode.SELECT)
@NotFound(action = NotFoundAction.IGNORE)
public Operation getOperation()
{
return this.operation;
}
}

我最初使用 Hibernate 4.3.9,然后尝试使用 Hibernate 5.1.0。两者都抛出相同的异常:

15:55:21,408 DEBUG [org.hibernate.cfg.annotations.TableBinder] Retrieving property com.icumed.ifactory3.dto.wip.JobOperation.operation
15:55:21,409 DEBUG [org.hibernate.jpa.HibernatePersistenceProvider] Unable to build entity manager factory
java.lang.ClassCastException: org.hibernate.mapping.Formula cannot be cast to org.hibernate.mapping.Column
at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:584)

Hibernate 的 TableBinder 类中没有任何内容引用公式。 Hibernate 是否只是不支持此功能,或者我使用了错误的注释,或者还有其他情况发生?

最佳答案

问题的根源似乎在协会的另一边。我本来就有这个

public class Operation extends AbstractOperation
{
@OneToMany(mappedBy="operation")
public Set<JobOperation> getJobOperations()
{
return this.jobOperations;
}
}

当我将其更改为以下内容时,它起作用了。

public class Operation extends AbstractOperation
{
@OneToMany
@JoinColumn(name="STANDARD_OPERATION_ID")
public Set<JobOperation> getJobOperations()
{
return this.jobOperations;
}
}

关于java - JPA @ManyToOne @JoinFormula 抛出 ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47065031/

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