hibernate里联合主键配置(多个字段一起作为主键)
- <hibernate-mapping package="com.hp.orm.bo">
- <class name="PropertyFileBsline" table="property_file_bsline">
- <composite-id name="Id" class="PropertyFileBslinePK">
- <key-property name="Bslineid" column="bslineid" type="string"/>
- <key-property name="Bslinepropertyid" column="bslinepropertyid"
- type="string"/>
- </composite-id>
- <property
- name="Bslinepropertyname"
- column="bslinepropertyname"
- type="string"
- not-null="true"
- length="20"/>
- <property
- name="Bslinepropertytype"
- column="bslinepropertytype"
- type="string"
- not-null="true"
- length="20"/>
- <property
- name="Flag"
- column="flag"
- type="string"
- not-null="true"
- length="10"/>
- </class>
- </hibernate-mapping>
Hibernate生成的主键类
- public class PropertyFileBslinePK extends BasePropertyFileBslinePK {
- private static final long serialVersionUID = 1L;
- /*[CONSTRUCTOR MARKER BEGIN]*/
- public PropertyFileBslinePK () {}
- public PropertyFileBslinePK (
- java.lang.String bslineid,
- java.lang.String bslinepropertyid) {
- super (
- bslineid,
- bslinepropertyid);
- }
- /*[CONSTRUCTOR MARKER END]*/
- }
查询单个主键时用HQL语句
- from PropertyFileBsline a where a.id.bslineid =?
结果报错:
NoClassDefFoundError: org/hibernate/exception/DataException
上网查了一下,说是hql语句的问题.
测试了大半天结果调试正常了,原来是a.id.bslineid =?中的bslineid 要写映射xml中的name,不能写PK类中的属性.
正确的HQL:
- from PropertyFileBsline a where a.id.Bslineid =?