-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: problem parsing configuration/hibernate.cfg.xml
PostPosted: Fri Aug 19, 2005 2:51 am 
Newbie

Joined: Tue Aug 16, 2005 8:12 am
Posts: 10
Hi,

I am trying out a very simple example in Hibernate but when I try to run the application it gives me the following error messages:
[java] net.sf.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml
[java] at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:958)
[java] at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:897)
[java] at Main.main(Unknown Source)
[java] Caused by: org.dom4j.DocumentException: hibernate.sourceforge.net Nested exception: hibernate.sourceforge.ne

[java] at org.dom4j.io.SAXReader.read(SAXReader.java:484)
[java] at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:953)
[java] ... 2 more
[java] Exception in thread "main"
[java] Java Result: 1

My hibernate.cfg.xml file is something like this:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:hsql:.</property>
<property name="connection.username">SA</property>
<property name="connection.password"></property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<mapping resource="keyword.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Any idea y is it happening? I will appreciate any help in regard to this.

Regards,
Medhavi.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 2:59 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
Correct your hibernate.cfg.cml file's attribute names as given below:


<only sample is given>

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory>
<!-- local connection properties -->
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/hibernate
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.username">uname</property>
<property name="hibernate.connection.password">pword</property>

<!-- dialect for MySQL -->
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.use_outer_join">true</property>
<mapping resource="User.hbm.xml" />
<mapping resource="Address.hbm.xml" />
<mapping resource="UserGroup.hbm.xml" />
<mapping resource="Qualification.hbm.xml" />
<mapping resource="House.hbm.xml" />
<mapping resource="Student.hbm.xml" />
</session-factory>
</hibernate-configuration>


It will work!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 3:02 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
for Hibernate 2.x, you have to replace org.hibernate..... by net.sf.hibernate


-Rgds,
Aru K


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 7:17 am 
Newbie

Joined: Tue Aug 16, 2005 8:12 am
Posts: 10
Hi,
Thanks for the reply.
I am using hibernate-2.0. The problem was in the DOCTYPE declaration in hibernate.cfg.xml I was mistakenly specifying "...hibernate-configuration-3.0.dtd" though I am using 2.0, I corrected that and it worked fine but now stucked on the next step.
Now its giving me error in the mapping file which I am using.
The error is as follows:
net.sf.hibernate.MappingException: Error reading resource: keyword.hbm.xml
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:339)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:1013)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:969)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:897)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:883)
at Main.main(Unknown Source)
Caused by: net.sf.hibernate.MappingException: duplicate import: Keyword
at net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:85)
at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:126)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:221)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1256)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:288)
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:336)
... 5 more
Exception in thread "main"
Java Result: 1

Any inputs on this??

Code in mapping file:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<!-- table created by: CREATE TABLE KEYWORDS ( ID IDENTITY, NAME VARCHAR(25) ); -->
<class name="Keyword"
table="keywords">
<id name="id"
type="integer"
column="id">
<generator class="increment"/>
</id>
<property name="name"
column="NAME"
not-null="true"
unique="true"
/>
</class>
</hibernate-mapping>

thnks,
Medhavi.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 10:00 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
this error means that you are importing Keyword.hbm.xml file twice into Configuration object.

Make sure you dont import this file twice.

HOW TO CHECK if u havent really imported twice or more?

1. Check if you havent mistakenly typed in .addClass(Keywork.class) line twice while creating session factory through configuration object.

2. Check your hibernate.cfg.xml file and make sure you dont have <mapping resource ..> tag twice or more

If you still get error, simple. You would have done both of above stated things simultaenously.

Only one step is needed to bring mapping into configuration.

Enjoy Hibernate!!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 12:24 am 
Newbie

Joined: Tue Aug 16, 2005 8:12 am
Posts: 10
Hi,

It worked :). I removed one mapping from main class but now it got trapped in another error..:(.

net.sf.hibernate.JDBCException: Cannot open connection
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:289)
at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3326)
at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3286)
at net.sf.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:40)
at net.sf.hibernate.transaction.JDBCTransactionFactory.beginTransaction(JDBCTransactionFactory.java:19)
at net.sf.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:2231)
at Main.main(Unknown Source)
Caused by: java.sql.SQLException: [b]The database is already in use by another process
[/b]at org.hsqldb.Trace.getError(Unknown Source)
at org.hsqldb.Trace.error(Unknown Source)
at org.hsqldb.Log.open(Unknown Source)
at org.hsqldb.Database$Logger.openLog(Unknown Source)
at org.hsqldb.Database.open(Unknown Source)
at org.hsqldb.Database.<init>(Unknown Source)
at org.hsqldb.jdbcConnection.openStandalone(Unknown Source)
at org.hsqldb.jdbcConnection.<init>(Unknown Source)
at org.hsqldb.jdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProv
01)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:286)
... 6 more
net.sf.hibernate.JDBCException: Cannot open connection
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:289)
at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3326)
at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3286)
at net.sf.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:40)
at net.sf.hibernate.transaction.JDBCTransactionFactory.beginTransaction(JDBCTransactionFactory.java:19)
at net.sf.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:2231)
at Main.main(Unknown Source)
Caused by: java.sql.SQLException: The database is already in use by another process
at org.hsqldb.Trace.getError(Unknown Source)
at org.hsqldb.Trace.error(Unknown Source)
at org.hsqldb.Log.open(Unknown Source)
at org.hsqldb.Database$Logger.openLog(Unknown Source)
at org.hsqldb.Database.open(Unknown Source)
at org.hsqldb.Database.<init>(Unknown Source)
at org.hsqldb.jdbcConnection.openStandalone(Unknown Source)
at org.hsqldb.jdbcConnection.<init>(Unknown Source)
at org.hsqldb.jdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProv
01)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:286)
... 6 more

I am using HSQL in-memory database and I don't think I can see any visible process using this database.

It will be great if you have the solution for this problem too....

Thanks,
Medhavi.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 1:58 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
Good to hear that you have solved the problem.

For your current one, please refer to HSQL reference.

And dont forget to give credit!!!!!

Thanks and Regards,
Aru K


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.