小编典典

在Hibernate中加入UserType

hibernate

在这种情况下,能否使休眠状态以“正确”的某个值来执行“正确的事情”?

from ClassA a, ClassB b
where a.prop = b.prop

问题是prop是联接表中具有不同表示形式的UserType。在表A中,它表示为整数,在表B中,它表示为char。因此,eq测试转换为看是否1 ==’a’或多或少,这是错误的,但由1或’a’表示的对象应该相同,因此它们应该比较为true。


阅读 438

收藏
2020-09-27

共1个答案

小编典典

我认为您可以使用<formula>映射文件中关系上的标记来执行此操作。

例如:

<many-to-one name="myClassB" class="ClassB">
  <formula>--Some SQL Expression that converts between ClassA.prop and ClassB.prop</formula>
</many-to-one>

我用它来关联两个表,其中一个使用整数,但将其关联到另一个表中的char字段。这可能不完全是您想要的,但是也许它将使您走上正确的轨道。

2020-09-27