| Author |
problem with hibernate and struts
|
dev Rana
Greenhorn
Joined: Sep 11, 2007
Posts: 5
|
|
hi i am learning hibernate. i have created one application with netbeans but getting exception like org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/test/users/Customer.hbm.xml in hibernateUtil.java code snippet public class HibernateUtil { private static final SessionFactory sessionFactory; static { try { // Create the SessionFactory from standard (hibernate.cfg.xml) // config file. sessionFactory = new Configuration().configure().buildSessionFactory(); } catch (Throwable ex) { // Log the exception. System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } } please help me
|
Warmest Regards<br />Dev Zala<br />Project Engineer
|
 |
Nishan Patel
Ranch Hand
Joined: Sep 07, 2008
Posts: 666
|
|
Hi, First of all check in your hibernate.cfg.xml. It should contains mapping tag like, <mapping resource="com/test/users/Customer.hbm.xml" /> That's it. This will only solve your problem. Thanks, Nishan Patel. Java Developer
|
Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5 Java Developer,My Blog
|
 |
Nishan Patel
Ranch Hand
Joined: Sep 07, 2008
Posts: 666
|
|
If you solve your problem then let me know. Thanks, Nishan Patel. Java Developer
|
 |
dev Rana
Greenhorn
Joined: Sep 11, 2007
Posts: 5
|
|
hi this is my hibernate.cfg.xml and <hibernate-configuration> <session-factory name="session1"> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sample</property> <property name="hibernate.show_sql">true</property> <property name="hibernate.current_session_context_class">thread</property> <mapping resource="com/test/users/Customer.hbm.xml"/> </session-factory> </hibernate-configuration and this is my customer.hbm.xml <hibernate-mapping auto-import="true" default-lazy="false"> <class name="sample.Customer" table="customer"> <id column="customer_id" name="CustomerId"> <generator class="increment" /> </id> <property column="discount_code" name="DiscountCode" /> <property column="zip" name="Zip"/> <property column="name" name="UserName" /> <property column="credit_limit" name="CreditLimit" /> <property column="addressline1" name="AddressLine1"/> <property column="addressline2" name="AddressLine2" /> <property column="city" name="City" /> <property column="email" name="EmailAddress"/> <property column="phone" name="Phone"/> <property column="fax" name="Fax"/> <property column="state" name="State" /> </class> </hibernate-mapping>
|
 |
dev Rana
Greenhorn
Joined: Sep 11, 2007
Posts: 5
|
|
and detailed exception is ERROR XMLHelper - Error parsing XML: XML InputStream(4) The content of element type "class" is incomplete, it must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(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)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)". 10:39:12,218 ERROR [action] - Servlet.service() for servlet action threw exception org.xml.sax.SAXParseException: The content of element type "class" is incomplete, it must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(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)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".
|
 |
Nishan Patel
Ranch Hand
Joined: Sep 07, 2008
Posts: 666
|
|
Hi, Please change your hbm.xml file like. <class name="com.printeverywhere.dto.Feedback" table="feedback" catalog="printeverywhere"> Thanks, Nishan Patel. Java Developer
|
 |
dev Rana
Greenhorn
Joined: Sep 11, 2007
Posts: 5
|
|
Hi Thanks Buddy !!! its working Regards Dev Zala
|
 |
Nishan Patel
Ranch Hand
Joined: Sep 07, 2008
Posts: 666
|
|
hi, You are welcome buddy. Thanks, Nishan Patel. Java Developer
|
 |
nimisha garg
Greenhorn
Joined: Jun 08, 2011
Posts: 2
|
|
Hi Nishan,
I am facing the same problem , Coudl you please help me in this
SEVERE: Error parsing XML: XML InputStream(11) The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(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)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".
|
 |
Hemant Thard
Ranch Hand
Joined: Dec 23, 2008
Posts: 113
|
|
hi Nimisha,
Welcome to java Ranch.
The problem is in your hbm file.
you have defined an attribute in your class element that is invalid.
All attribute defined must be of type
"(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(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)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".
Regards,
Hemant.
|
 |
nimisha garg
Greenhorn
Joined: Jun 08, 2011
Posts: 2
|
|
Hi Hemant,
Thanks for the reply.
I am sorry but i didnt get what is teh issue with the hbm file .
I am just pasting the contents of the file.
<?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>
<meta attribute="sync-DAO">true</meta>
<class name="example.Hib_Report" table="M_REPORT">
<property name="REP_ID"/>
<property name="REP_TABLES_NAME"/>
<property name="REP_TABLES_COL"/>
</class>
</hibernate-mapping>
is there anything I am misisng over here
|
 |
Hemant Thard
Ranch Hand
Joined: Dec 23, 2008
Posts: 113
|
|
Hi Nimisha,
you have not defined identifier for table in hbm file.
identifier is used to uniquely identify rows in table.
you can declare identifier using any of the following element
id or composite-id.
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3563
|
|
Mr. Ashish Mathur, Your post was moved to a new topic.
|
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
|
 |
 |
|
|
subject: problem with hibernate and struts
|
|
|