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("
[email protected]");
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