hibernate - Error reading xml - wrong mapping for one to many relation -
i using intellij thought develop javaee applications.
i have created mysql database 3 tables (customer, product, category). generated hibernate configuration using wizard.
i have next issue:
févr. 19, 2013 9:40:53 pm org.hibernate.cfg.configuration addresource info: hhh000221: reading mappings resource: smdatabase/smcategoryentity.hbm.xml exception in thread "main" org.hibernate.invalidmappingexception: unable read xml @ org.hibernate.internal.util.xml.mappingreader.readmappingdocument(mappingreader.java:106) @ org.hibernate.cfg.configuration.add(configuration.java:477) @ org.hibernate.cfg.configuration.add(configuration.java:473) @ org.hibernate.cfg.configuration.add(configuration.java:646) @ org.hibernate.cfg.configuration.addresource(configuration.java:729) @ org.hibernate.cfg.configuration.parsemappingelement(configuration.java:2105) @ org.hibernate.cfg.configuration.parsesessionfactory(configuration.java:2077) @ org.hibernate.cfg.configuration.doconfigure(configuration.java:2057) @ org.hibernate.cfg.configuration.doconfigure(configuration.java:2010) @ org.hibernate.cfg.configuration.configure(configuration.java:1925) @ org.hibernate.cfg.configuration.configure(configuration.java:1904) @ main.getsession(main.java:39) @ main.main(main.java:49) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:601) @ com.intellij.rt.execution.application.appmain.main(appmain.java:120) caused by: org.dom4j.documentexception: null nested exception: null @ org.dom4j.io.saxreader.read(saxreader.java:484) @ org.hibernate.internal.util.xml.mappingreader.readmappingdocument(mappingreader.java:76) ... 17 more process finished exit code 1
here tables definition:
create table client ( id int not null primary key, email varchar(500), password varchar(500), shipping_address varchar(500), shipping_postal_code varchar(500), shipping_country varchar(500), when_created timestamp default current_timestamp ) engine=innodb; create table category( id int not null auto_increment primary key, name varchar(500) not null, when_created timestamp default current_timestamp ) engine=innodb; create table product ( id int not null auto_increment primary key, cost decimal, name varchar(500) not null, category_id int not null, product_index int not null default 0, when_created timestamp default current_timestamp, foreign key (category_id) references category(id) ) engine=innodb;
and hbm.xmls generated (3 different files):
<?xml version='1.0' encoding='utf-8'?> <hibernate-mapping xmlns="http://www.hibernate.org/xsd/hibernate-mapping" xsi:schemalocation="http://www.hibernate.org/xsd/hibernate-mapping http://www.hibernate.org/xsd/hibernate-mapping/hibernate-mapping-4.0.xsd" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <class name="smdatabase.smproductentity" table="product" catalog="supmarket"> <id name="id"> <column name="id" sql-type="int" length="10" not-null="true"/> </id> <property name="price"> <column name="price" sql-type="decimal" length="10"/> </property> <property name="name"> <column name="name" sql-type="varchar" length="500" not-null="true"/> </property> <property name="categoryid"> <column name="category_id" sql-type="int" length="10" not-null="true"/> </property> <property name="whencreated"> <column name="when_created" sql-type="timestamp" length="19" not-null="true"/> </property> <many-to-one name="category" class="smdatabase.smcategoryentity"/> </class> </hibernate-mapping> <!-- file 2 --> <?xml version='1.0' encoding='utf-8'?> <hibernate-mapping xmlns="http://www.hibernate.org/xsd/hibernate-mapping" xsi:schemalocation="http://www.hibernate.org/xsd/hibernate-mapping http://www.hibernate.org/xsd/hibernate-mapping/hibernate-mapping-4.0.xsd" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <class name="smdatabase.smcategoryentity" table="category" > <id name="id"> <column name="id" sql-type="int" length="10" not-null="true"/> </id> <property name="name"> <column name="name" sql-type="varchar" length="500" not-null="true"/> </property> <property name="whencreated"> <column name="when_created" sql-type="timestamp" length="19" not-null="true"/> </property> <list name="categoryproducts" inverse="true" table="product"> <key column="category_id" /> <list-index column="product_index" base="1"/> <one-to-many not-found="ignore" class="smdatabase.smproductentity"/> </list> </class> </hibernate-mapping> <!-- file 3 --> <?xml version='1.0' encoding='utf-8'?> <hibernate-mapping xmlns="http://www.hibernate.org/xsd/hibernate-mapping" xsi:schemalocation="http://www.hibernate.org/xsd/hibernate-mapping http://www.hibernate.org/xsd/hibernate-mapping/hibernate-mapping-4.0.xsd" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <class name="smdatabase.smcustomerentity" table="customer" schema="" catalog="supmarket"> <id name="id"> <column name="id" sql-type="int" length="10" not-null="true"/> </id> <property name="email"> <column name="email" sql-type="varchar" length="500"/> </property> <property name="password"> <column name="password" sql-type="varchar" length="500"/> </property> <property name="shippingaddress"> <column name="shipping_address" sql-type="varchar" length="500"/> </property> <property name="shippingpostalcode"> <column name="shipping_postal_code" sql-type="varchar" length="500"/> </property> <property name="shippingcountry"> <column name="shipping_country" sql-type="varchar" length="500"/> </property> <property name="whencreated"> <column name="when_created" sql-type="timestamp" length="19" not-null="true"/> </property> </class> </hibernate-mapping>
i have changed property in category table. after has been generated was:
<list name="categoryproducts" inverse="true"> <key /> <one-to-many not-found="ignore" class="smdatabase.smproductentity"/> </list>
i totally lost. help me please?
i'm not sure xsd mention valid:
http://www.hibernate.org/xsd/hibernate-mapping/hibernate-mapping-4.0.xsd
you should stick following, if using hibernate 4:
<!doctype hibernate-mapping public "-//hibernate/hibernate mapping dtd 3.0//en" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping> ... </hibernate-mapping>
hibernate java-ee intellij-idea
No comments:
Post a Comment