没有新类的Hibernate Compsite Key [英] Hibernate Compsite Key without new class

查看:145
本文介绍了没有新类的Hibernate Compsite Key的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的hibernate mapping

 < class name =com.domain.OtherAccounttable =ACCOUNT> ; 
< composite-id>
< / composite-id>
< property name =accholder>< / property>
< / class>

我不想为复合键创建单独的类。所以,acctype和accnum只是OtherAccount类的一部分。类实现可序列化的接口和hashCode()和equals()方法。

我可以创建新对象并使用session.save()持久保存它。
但是我如何检索现有对象?在session.get()方法中如何指定组合键?

 在session.get(OtherAccount.class,如何指定组合KEY HERE)


解决方案

创建一个 OtherAccount 并设置这两个字段。 Hibernate并不在乎实例的字段多于需要。


I have simple hibernate mapping

      <class name="com.domain.OtherAccount" table="ACCOUNT">
          <composite-id >
            <key-property name="acctype" column="acctype" type="java.lang.Character"></key-property>
            <key-property name="accnum" column="accnum" type="java.lang.Integer"></key-property>
          </composite-id>
         <property name="accholder"></property>
      </class>

I do not want to create separate class for Composite Key. So, acctype and accnum are part of OtherAccount class only. Class implements serializable interface and hashCode() and equals() methods.

I am able to create new object and persist it using, session.save(). But how can I retrieve existing object ? In session.get() method how to specify composite key ?

  In session.get(OtherAccount.class, HOW TO SPECIFY COMPOSITE KEY HERE )

解决方案

Create an instance of OtherAccount and set just those two fields. Hibernate doesn't care that the instance has more fields than it needs.

这篇关于没有新类的Hibernate Compsite Key的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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