-->
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.  [ 14 posts ] 
Author Message
 Post subject: Hibernate 3 MappingException
PostPosted: Thu Apr 28, 2005 5:54 am 
Newbie

Joined: Tue Apr 26, 2005 6:25 am
Posts: 6
Hi List,
Last few days I am trying to run sample hibernate program but everytime I face with same error... I have tried numerous combinations but I always get a mapping exception :-(......pl tell whats wrong
Hibernate Version 3 DB: Oracle 9i /Hsqldb 1.7.1,1.8.0 IDE: Ecllipse: .hibernateSynchronizer3/and by hand/ant

a) Mapping document
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="test">
<class
name="Users"
table="USERS"
>

<property
name="Username"
column="USERNAME"
type="string"
not-null="false"
length="50"
/>
<property
name="Groupid"
column="GROUPID"
type="string"
not-null="false"
length="10"
/>


</class>
</hibernate-mapping>

b) Calling Class
package users;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import users.hiber.*;
//import test.hibernate.Product;

// use as
// java test.InsertProduct name amount price
public class insertUsers {

public static void main(String[] args)
throws Exception {

// 1. Build a Product
Users u = new Users();
u.setName("Gaurav Prasad");
//u.setPassword("Comnet");
//u.setEmailid("gauravp@hclcomnet.co.in");
u.setGroupid("234");

/*p.setName(args[0]);
p.setAmount(Integer.parseInt(args[1]));
p.setPrice(Double.parseDouble(args[2]));
*/

// 2. Fire up Hibernate
Configuration cfg = new Configuration()
.addClass(Users.class);
SessionFactory sf = cfg.buildSessionFactory();

System.out.println(u);
// 3. Open Session
Session sess = sf.openSession();

// 4. Save Product and close Session
Transaction t = sess.beginTransaction();
sess.save(u);
t.commit();
sess.close();
System.out.println(u);
}
}

c) Pojo Class
package users.hiber;

/**
* @author gp
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class Users {


private String Name;
//private String Password;
// private String Emailid ;
// private String Id;
private String Groupid;

/* public String getid() {
return Id;
}

public void setId(String Id) {
this.Id = Id;
}
*/
public String Getname() {
return Name;
}

public void setName(String Name) {
this.Name = Name;
}


/* public String getEmailId() {
return EmailId;
}

public voId setEmailId(String EmailId) {
this.EmailId =EmailId;
}

public String getPassword() {
return Password;
}

public voId setPassword(String Password) {
this.Password =Password;
}
*/
public String getGroupid() {
return Groupid;
}

public void setGroupid(String Groupid) {
this.Groupid = Groupid;
}
}

d) Stack trace
Exception in thread "main" org.hibernate.MappingException: Error reading resource: users/hiber/Users.hbm.xml
at org.hibernate.cfg.Configuration.addClass(Configuration.java:467)
at users.insertUsers.main(insertUsers.java:31)
Caused by: org.hibernate.MappingException: org.dom4j.DocumentException: No route to host Nested exception: No route to host
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:404)
at org.hibernate.cfg.Configuration.addClass(Configuration.java:464)
... 1 more
Caused by: org.dom4j.DocumentException: No route to host Nested exception: No route to host
at org.dom4j.io.SAXReader.read(SAXReader.java:353)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:394)
... 2 more




R


Top
 Profile  
 
 Post subject: Hibernate 3 MappingException
PostPosted: Thu Apr 28, 2005 6:12 am 
Newbie

Joined: Thu Dec 09, 2004 4:26 am
Posts: 19
Location: Yorkshire, UK
Could it be that the hibernate configuration,not the mapping config but applicationContext.xml or your equiv, cannot see the mapping document?

The "Nested exception: No route to host" will be the problem. Could you post the context configuration?

Tim


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 6:48 am 
Regular
Regular

Joined: Wed Feb 02, 2005 6:33 am
Posts: 70
Your doctype declaration is referring to the hibernate 2.0 dtd. This isn't included in hibernate 3 jar, so the xml verifier tries to find it from the url in the doctype. Your computer can't access that, and is throwing an exception.

Change the doctype to:

Code:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >


Top
 Profile  
 
 Post subject: Re: Hibernate 3 MappingException
PostPosted: Thu Apr 28, 2005 6:56 am 
Newbie

Joined: Tue Apr 26, 2005 6:25 am
Posts: 6
weliwarmer wrote:
Could it be that the hibernate configuration,not the mapping config but applicationContext.xml or your equiv, cannot see the mapping document?

The "Nested exception: No route to host" will be the problem. Could you post the context configuration?

Tim

Tim by applicationContext.xml do you mean
<?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:oracle:thin:@hcl-node5:1521:cummins</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.username">cummins</property>
<property name="hibernate.connection.password">cummins</property>
<!-- property name="hibernate.connection.pool_size"></property -->

<!-- dialect for Oracle 9 -->
<property name="dialect">net.sf.hibernate.dialect.Oracle9Dialect</property>

<property name="hibernate.show_sql">false</property>
<property name="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactory</property>
</session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject: DTD
PostPosted: Thu Apr 28, 2005 7:24 am 
Newbie

Joined: Thu Dec 09, 2004 4:26 am
Posts: 19
Location: Yorkshire, UK
Colin's right. Both doctypes (for configuration and mapping) need to refer to version 3.


Top
 Profile  
 
 Post subject: Dialect error
PostPosted: Thu Apr 28, 2005 7:31 am 
Newbie

Joined: Tue Apr 26, 2005 6:25 am
Posts: 6
CollinL wrote:
Your doctype declaration is referring to the hibernate 2.0 dtd. This isn't included in hibernate 3 jar, so the xml verifier tries to find it from the url in the doctype. Your computer can't access that, and is throwing an exception.

Change the doctype to:

Code:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >


Thanks Collin for pointing this out ...but I am still getting Dialect error

error
xception in thread "main" org.hibernate.HibernateException: The dialect was not set. Set the property hibernate.dialect.
at org.hibernate.dialect.Dialect.getDialect(Dialect.java:477)
at org.hibernate.dialect.Dialect.getDialect(Dialect.java:499)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:51)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1505)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1053)
at users.insertUsers.main(insertUsers.java:33)

My Hibernate cfg 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-configuration>
<session-factory >

<!-- local connection properties -->
<property name="hibernate.connection.url">jdbc:oracle:thin:@hcl-node5:1521:cummins</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.username">cummins</property>
<property name="hibernate.connection.password">cummins</property>
<!-- property name="hibernate.connection.pool_size"></property -->

<!-- dialect for Oracle 9 -->
<property name="dialect">net.sf.hibernate.dialect.Oracle9Dialect</property>

<property name="hibernate.show_sql">false</property>
<property name="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactory</property>
</session-factory>
</hibernate-configuration>


Proferty file

hibernate.dialect=net.sf.hibernate.dialect.Oracle9Dialect
hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver

hibernate.connection.url=jdbc:oracle:thin:@hcl-node5:1521:cummins

hibernate.connection.username=cummins

hibernate.connection.password=cummins


I have tried changing dialect to org.hibernate.dialect.Oracle9Dialect but I get same error


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 7:51 am 
Regular
Regular

Joined: Wed Feb 02, 2005 6:33 am
Posts: 70
In hibernate 3, the packages have been changed, so instead of using net.sf.* use org.*, so your hibernate configuration becomes:

Code:
<?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-configuration>
<session-factory >

<!-- local connection properties -->
<property name="hibernate.connection.url">jdbc:oracle:thin:@hcl-node5:1521:cummins</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.username">cummins</property>
<property name="hibernate.connection.password">cummins</property>
<!-- property name="hibernate.connection.pool_size"></property -->

<!-- dialect for Oracle 9 -->
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>

<property name="hibernate.show_sql">false</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
</session-factory>
</hibernate-configuration>


Note that both the dialect and the transaction.factory_class properties have changed.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 8:12 am 
Newbie

Joined: Tue Apr 26, 2005 6:25 am
Posts: 6
CollinL wrote:
In hibernate 3, the packages have been changed, so instead of using net.sf.* use org.*, so your hibernate configuration becomes:

Code:
<?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-configuration>
<session-factory >

<!-- local connection properties -->
<property name="hibernate.connection.url">jdbc:oracle:thin:@hcl-node5:1521:cummins</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.username">cummins</property>
<property name="hibernate.connection.password">cummins</property>
<!-- property name="hibernate.connection.pool_size"></property -->

<!-- dialect for Oracle 9 -->
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>

<property name="hibernate.show_sql">false</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
</session-factory>
</hibernate-configuration>


Note that both the dialect and the transaction.factory_class properties have changed.


I have chaged this ...but still I am getting error I wonder why ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 8:28 am 
Regular
Regular

Joined: Wed Feb 02, 2005 6:33 am
Posts: 70
A session should be instantiated by, e.g.

Code:
// Create a configuration object
Configuration c = new Configuration();
// Get the config object to load the hibernate.cfg.xml
c = c.configure();
SessionFactory sf = c.buildSessionFactory();
Session s = sf.openSession();


If you don't call teh configure() method, the configuration document won't be loaded.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 9:07 am 
Newbie

Joined: Tue Apr 26, 2005 6:25 am
Posts: 6
CollinL wrote:
A session should be instantiated by, e.g.

Code:
// Create a configuration object
Configuration c = new Configuration();
// Get the config object to load the hibernate.cfg.xml
c = c.configure();
SessionFactory sf = c.buildSessionFactory();
Session s = sf.openSession();


If you don't call teh configure() method, the configuration document won't be loaded.

thanks for assistance it now picks the dialect but I am now I am getting mapping error with hibernate.cfg.xml !!
error

Exception in thread "main" org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1222)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1161)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1147)
at users.hiber.insertUsers.main(insertUsers.java:34)
Caused by: org.dom4j.DocumentException: No route to host Nested exception: No route to host
at org.dom4j.io.SAXReader.read(SAXReader.java:353)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
... 3 more

<?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-configuration>
<session-factory >

<!-- local connection properties -->
<property name="hibernate.connection.url">jdbc:oracle:thin:@hcl-node5:1521:cummins</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.username">cummins</property>
<property name="hibernate.connection.password">cummins</property>
<!-- property name="hibernate.connection.pool_size"></property -->

<!-- dialect for Oracle 9 -->
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>

<property name="hibernate.show_sql">false</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
</session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 9:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
"Hibernate3 Mapping Exception"

http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd

See anything obvious?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 9:17 am 
Regular
Regular

Joined: Wed Feb 02, 2005 6:33 am
Posts: 70
Doctype again :)
the doctype for mapping and configuration documents is different, for configuration it should be:

Code:
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 29, 2005 7:10 am 
Newbie

Joined: Tue Apr 26, 2005 6:25 am
Posts: 6
CollinL wrote:
Doctype again :)
the doctype for mapping and configuration documents is different, for configuration it should be:

Code:
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">


thanks Collin .....I am getting problem parsing configuration/hibernate.cfg.xml this time.....but hibernate 2 code is running fine ...I hope I just could make hb 3 program run .....

Exception in thread "main" org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1222)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1161)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1147)
at users.insertUsers.main(insertUsers.java:33)
Caused by: org.dom4j.DocumentException: No route to host Nested exception: No route to host
at org.dom4j.io.SAXReader.read(SAXReader.java:353)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
... 3 more


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

<hibernate-configuration>

<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory
name="java:hibernate/SessionFactory">

<!-- properties -->
<property name="connection.datasource">java:/comp/env/jdbc/MyDB</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">false</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>

<!-- mapping files -->
<mapping resource="org/hibernate/auction/Item.hbm.xml"/>
<mapping resource="org/hibernate/auction/Bid.hbm.xml"/>

<!-- cache settings -->
<class-cache class="org.hibernate.auction.Item" usage="read-write"/>
<class-cache class="org.hibernate.auction.Bid" usage="read-only"/>
<collection-cache class="org.hibernate.auction.Item.bids" usage="read-write"/>

</session-factory>

</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 29, 2005 9:05 am 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
You need to have this as your DTD specifier:
Code:
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">


You have this:
Code:
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">


You are missing the " 3.0".


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 14 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.