[英]Composite primary key issue in hibernate
I am creating a hibernate application in which i want to create a composite primary key . 我正在创建一个休眠应用程序,在其中我想创建一个复合主键 。 Following is the mapping file I have written:
以下是我编写的映射文件:
<?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>
But I am getting exception as follows: 但是我得到如下异常:
- 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
So i want to know what is missing to be provided in this code.I searched on net but didn't find anything useful.What does it means? 所以我想知道这段代码中缺少什么内容。我在网上搜索但没有发现有用的东西,这意味着什么?
There are many things : 有很多事情 :
1/ change your dtd from : 1 /从更改您的dtd:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
to: 至:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
this will remove the warning about obsolete hibernate namespace 这将删除有关过时的休眠名称空间的警告
2/ Remove not-null attribute for key-property, this attribute does not exists for key-property since a PK property cannot be null. 2 /删除密钥属性的not-null属性,因为PK属性不能为null,所以该属性对于密钥属性不存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.