Hibernate联合主键 以及根据联合主键中字段查询

hibernate里联合主键配置
  1. package="com.boise">  
  2.      name="PropertyFileBsline" table="property_file_bsline">  
  3.         name="Id" class="PropertyFileBslinePK">  
  4.            name="Bslineid" column="bslineid" type="string"/>  
  5.            name="Bslinepropertyid" column="bslinepropertyid"  
  6.     type="string"/>  
  7.          
  8.           
  9.           name="Bslinepropertyname"  
  10.           column="bslinepropertyname"  
  11.           type="string"  
  12.           not-null="true"  
  13.           length="20"/>  
  14.          
  15.           name="Bslinepropertytype"  
  16.           column="bslinepropertytype"  
  17.           type="string"  
  18.           not-null="true"  
  19.           length="20"/>  
  20.          
  21.           name="Flag"   
  22.           column="flag"  
  23.           type="string"  
  24.           not-null="true"  
  25.          length="10"/>  
  26.          
  27.   

Hibernate生成的主键类

  1. public class PropertyFileBslinePK extends BasePropertyFileBslinePK {   
  2.     private static final long serialVersionUID = 1L;   
  3.   
  4. /*[CONSTRUCTOR MARKER BEGIN]*/  
  5.     public PropertyFileBslinePK () {}   
  6.        
  7.     public PropertyFileBslinePK (   
  8.          java.lang.String bslineid,   
  9.          java.lang.String bslinepropertyid) {   
  10.   
  11.         super (   
  12.              bslineid,   
  13.              bslinepropertyid);   
  14.      }   
  15. /*[CONSTRUCTOR MARKER END]*/  
  16.   

查询单个主键时用HQL语句
  1. from PropertyFileBsline a where a.id.bslineid =?  
from PropertyFileBsline a where a.id.bslineid =?
结果报错:
NoClassDefFoundError: org/hibernate/exception/DataException
上网查了一下,说是hql语句的问题.
测试了大半天结果调试正常了,原来是a.id.bslineid =?中的bslineid 要写映射xml中的name,不能写PK类中的属性.
正确的HQL:
  1. from PropertyFileBsline a where a.id.Bslineid =?  
from PropertyFileBsline a where a.id.Bslineid =?


你可能感兴趣的:(Hibernate)