JPA @ManyToOne @JoinFormula 抛出 ClassCastException
JPA @ManyToOne @JoinFormula throwing ClassCastException
我正在尝试使用 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 class 中没有任何内容涉及公式。 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;
}
}
我正在尝试使用 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 class 中没有任何内容涉及公式。 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;
}
}