File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml" Watch "org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml" New topic
Author

org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml

Nidhi Bansal
Greenhorn

Joined: Oct 11, 2012
Posts: 2
i got this code online..bt its giving me this exception.please help

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1291)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1230)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1216)
at com.mycompany.ContactManager.main(ContactManager.java:21)
Caused by: org.dom4j.DocumentException: www.hibernate.org Nested exception: www.hibernate.org
at org.dom4j.io.SAXReader.read(SAXReader.java:353)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1286)
... 3 more




here's my code

Hibernate configuration file:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hibernate_ex</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<mapping resource="com/mycompany/Contact.hbm.xml"></mapping>
</session-factory>
</hibernate-configuration>

package com.mycompany;

public class Contact {
private int id;
private String name;
private String email;
private String address;
private String telephone;

public Contact() {

}

public Contact(int id, String name, String email, String address,
String telephone) {
this.id = id;
this.name = name;
this.email = email;
this.address = address;
this.telephone = telephone;
}

public Contact(String name, String email, String address, String telephone) {
this.name = name;
this.email = email;
this.address = address;
this.telephone = telephone;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getName() {
return name;
}

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

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public String getTelephone() {
return telephone;
}

public void setTelephone(String telephone) {
this.telephone = telephone;
}
}


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.mycompany">

<class name="Contact" table="CONTACT">
<id name="id" column="CONTACT_ID">
<generator class="increment"/>
</id>
<property name="name" type="string" column="NAME"/>
<property name="email"/>
<property name="address"/>
<property name="telephone"/>

</class>


Nidhi Bansal
Greenhorn

Joined: Oct 11, 2012
Posts: 2
the remaining code:

</hibernare-maping>

Contact Manager class

package com.mycompany;

import java.io.Serializable;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

/**
* A sample program that demonstrates how to perform simple CRUD operations
* with Hibernate framework.
* @author www.codejava.net
*
*/
public class ContactManager {

public static void main(String[] args) {
// loads configuration and creates a session factory
Configuration configuration = new Configuration().configure();
ServiceRegistryBuilder registry = new ServiceRegistryBuilder();
registry.applySettings(configuration.getProperties());
ServiceRegistry serviceRegistry = registry.buildServiceRegistry();
SessionFactory sessionFactory = configuration.buildSessionFactory();

// opens a new session from the session factory
Session session = sessionFactory.openSession();
session.beginTransaction();

// persists two new Contact objects
Contact contact1 = new Contact("Nam", "hainatu@gmail.com", "Vietnam", "0904277091");
session.persist(contact1);

Contact contact2 = new Contact("Bill", "bill@gmail.com", "USA", "18001900");
Serializable id = session.save(contact2);
System.out.println("created id: " + id);

// loads a new object from database
Contact contact3 = (Contact) session.get(Contact.class, new Integer(1));
if (contact3 == null) {
System.out.println("There is no Contact object with id=1");
} else {
System.out.println("Contact3's name: " + contact3.getName());
}

// loads an object which is assumed exists
Contact contact4 = (Contact) session.load(Contact.class, new Integer(4));
System.out.println("Contact4's name: " + contact4.getName());

// updates a loaded instance of a Contact object
Contact contact5 = (Contact) session.load(Contact.class, new Integer(5));
contact5.setEmail("info1@company.com");
contact5.setTelephone("1234567890");
session.update(contact5);

// updates a detached instance of a Contact object
Contact contact6 = new Contact(3, "Jobs", "jobs@applet.com", "Cupertino", "0123456789");
session.update(contact6);

// deletes an object
Contact contact7 = new Contact();
contact7.setId(7);
session.delete(contact7);

// deletes a loaded instance of an object
Contact contact8 = (Contact) session.load(Contact.class, new Integer(8));
session.delete(contact8);

// commits the transaction and closes the session
session.beginTransaction().commit();
session.close();

}

}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml