2012-08-10 61 views
0

这是我的hbm.xml文件结构。休眠组合键中的所有列 - 不返回POJO对象

<hibernate-mapping> 
<class name="customer" table="Customer" schema="Schem"> 
    <composite-id name="id" class="Customerid"> 
     <key-property name="code" type="java.lang.String"> 
      <column name="CODE" length="10" /> 
     </key-property> 
     <key-property name="name" type="java.lang.String"> 
      <column name="NAME" length="10" /> 
     </key-property> 
     <key-property name="address" type="java.lang.String"> 
      <column name="ADDRESS" length="100" /> 
     </key-property> 
     <key-property name="contactnumber" type="java.lang.String"> 
      <column name="CONTACTNUMBER" length="15" /> 
     </key-property> 
    </composite-id> 
</class> 
</hibernate-mapping> 

但在数据库中,如果一行中的任何一列是空的。那么hibernate不会返回任何Customer对象并返回null。我猜测是因为所有的列都在复合标识符中,这就是为什么它返回空对象,如果该列中的任何一列是空的。 如何获得休眠POJO对象客户只有代码值可用?

+0

我的意思是复合键具有不属于主键的列。但我不知道如何通过仅使用'代码'列来获取客户对象。 – Jignesh 2012-08-10 13:56:18

回答

0

一个ID /主键必须不为空并且是唯一。只包括在compositeId映射中构成主键的列。要通过id获得一个实例,请使用

Customer customer = session.get(Customer.class, new Customer(<id properties));