在我的應用程序中,我沒有在一個表中使用主鍵列。我將其視爲代理鍵並嘗試使用tag.but我得到了異常。如果Hibernate的表中沒有ID列,該怎麼辦?
**"org.hibernate.MappingException: Error reading resource:
com/mapping/FamilyDetails.hbm.xml"**
**Caused by: org.xml.sax.SAXParseException:
The content of element type "class" must match "
(meta*,subselect?,cache?,synchronize*,comment?,
(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,
(property|many-to-one|one-to-one|component|dynamic-
component|properties|any|map|set|list|bag|idbag|array|
primitive-array|query-list)*,
((join*,subclass*)|joined-subclass*|union-subclass*),loader?,
sql-insert?,sql-update?,sql-delete?,filter*)".**
映射文件:-FamilyDetails.hbm.xml
<class name="com.beans.FamillyDetails"
table="personal_fmly_dtls" proxy="com.aims.beans.FamillyDetails">
<natural-id>
<property name="systemid" />
</natural-id>
<property name="membername"
type="java.lang.String" column="membername" not-null="true" />
<property name="relation"
type="java.lang.String" column="relation" not-null="true" />
<property name="dateOfBirth"
type="java.util.Date" column="dateofbirth" not-null="true" />
<many-to-one name="Personal" column="pid" class="com.aims.beans.Personal"/>
</class>
<?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="com.aims.beans.Personal"
table="personalinfo" proxy="com.aims.beans.Personal">
<id name="pid" column="pid" type="java.lang.Integer">
<generator class="sequence">
<param name="sequence">personal_seq</param>
</generator>
</id>
<property name="name"
type="java.lang.String" column="name" not-null="true" />
<property name="deptno"
type="java.lang.Integer" column="DEPTNO" not-null="true" />
<component name="permentaddress" class="com.aims.beans.Address">
<property name="homeAddress1" type="java.lang.String" column="pddress1"/>
<property name="homeAddress2" type="java.lang.String" column="pddress2"/>
<property name="homecity" type="java.lang.String" column="pcity"/>
<property name="homeState" type="java.lang.String" column="pstate"/>
</component>
<set name="famildtlslst">
<key column="pid" not-null="true"/>
<one-to-many class="com.aims.beans.FamillyDetails"/>
</set>
<join table="address">
<key column="pid" />
<component name="Address" class="com.aims.beans.Address">
<property name="homeAddress1"
type="java.lang.String" column="HomeAddress1"/>
<property name="homeAddress2"
type="java.lang.String" column="HomeAddress2"/>
<property name="homecity"
type="java.lang.String" column="homecity"/>
<property name="homeState"
type="java.lang.String" column="homestate"/>
</component>
</join>
請幫助我。
java hibernate中xml-mapping過時了嗎?我的意思是,在編輯器和重構工具的幫助下,寫起來很容易。它從實體實現中分離映射。我也不確定你是否可以用註釋做所有你可以用xml做的事情。但我不熟悉java,我正在使用NHibernate和C#。 – 2012-07-06 12:49:10