UserType在Hibernate中加入 [英] UserType join in Hibernate

查看:101
本文介绍了UserType在Hibernate中加入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



Is it possible to make hibernate do "the right thing" for some value of "right" in this situation?

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

事情是该prop是在连接表中具有不同表示形式的UserType。在表A中它表示为一个整数,在表B中它表示为一个字符。所以eq测试可以看到1 =='a'是否或多或少,这是错误的,但由1或'a'表示的对象应该是相同的,所以它们应该比较真实。

The thing is that prop is a UserType with different representation in the joined tables. In table A it is represented as an integer and in table B it is represented as a char. So the eq test translates to see if 1 == 'a' more or less, which is false but the object represented by 1 or 'a' should is the same so they should compare true.

推荐答案

我认为你可以在映射文件中的关系上使用< formula> 标记来完成此操作。

I think you can do this using a <formula> tag on the relationship in your mapping file.

例如:

For example:

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

我用这个关联了两个表,其中一个使用了整数,但将它与char字段在另一个表中。这可能不是你正在寻找的东西,但也许它会让你走上正轨。

I've used this to associate two tables where one used an integer, but associated it to a char field in another table. This might not be exactly what you're looking for, but maybe it will put you on the right track.

这篇关于UserType在Hibernate中加入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆