我正在创建一个hibernate应用程序,我想在其中创建一个复合主键。以下是我写的映射文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Fold.ChildrenPark" table="ChildrenPark">
<composite-id>
<key-property name="date" not-null="true"/>
<key-property name="valveOffTime" not-null="true"/>
<key-property name="valveOnTime" not-null="true"/>
</composite-id>
<property name="overHeadTankLevelAfterFilling"/>
<property name="overHeadTankLevelBeforeFilling"/>
<property name="rank"/>
</class>
</hibernate-mapping>
但我得到的例外情况如下:
- 1689 [http-listener-1(4)] ERROR org.hibernate.util.xml.ErrorLogger -
Error parsing XML (11) : Attribute "not-null" must be declared for
element type "key-property". Severe: 1717 [http-listener-1(4)] WARN
org.hibernate.util.DTDEntityResolver - recognized obsolete hibernate
namespace http://hibernate.sourceforge.net/. Use namespace
http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6
Migration Guide! Severe: 1719 [http-listener-1(4)] ERROR
org.hibernate.util.xml.ErrorLogger - Error parsing XML (2) :
Attribute "not-null" must be declared for element type
"key-property". Info: Exception in insertion of data:
org.hibernate.InvalidMappingException: Unable to read XML
所以我想知道这段代码中缺少什么。我在网上搜索但没有找到任何有用的东西。这意味着什么?
答案 0 :(得分:0)
有很多事情:
1 /改变你的dtd:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
为:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
这将删除有关过时的hibernate名称空间
的警告2 /删除key-property的not-null属性,key属性不存在此属性,因为PK属性不能为null。