Win a copy of Android Programming: The Big Nerd Ranch Guide this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

Nidhi Bansal
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got this code 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(
at org.hibernate.cfg.Configuration.configure(
at org.hibernate.cfg.Configuration.configure(
at com.mycompany.ContactManager.main(
Caused by: org.dom4j.DocumentException: Nested exception:
at org.hibernate.cfg.Configuration.doConfigure(
... 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"
<!-- 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>

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) { = id; = name; = email;
this.address = address;
this.telephone = telephone;

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

public int getId() {
return id;

public void setId(int id) { = id;

public String getName() {
return name;

public void setName(String name) { = name;

public String getEmail() {
return email;

public void setEmail(String 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"

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

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


Nidhi Bansal
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the remaining code:


Contact Manager class

package com.mycompany;


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
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();
ServiceRegistry serviceRegistry = registry.buildServiceRegistry();
SessionFactory sessionFactory = configuration.buildSessionFactory();

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

// persists two new Contact objects
Contact contact1 = new Contact("Nam", "", "Vietnam", "0904277091");

Contact contact2 = new Contact("Bill", "", "USA", "18001900");
Serializable id =;
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));

// updates a detached instance of a Contact object
Contact contact6 = new Contact(3, "Jobs", "", "Cupertino", "0123456789");

// deletes an object
Contact contact7 = new Contact();

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

// commits the transaction and closes the session


  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!