File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Getting error -problem parsing configuration/hibernate.cfg.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Getting error -problem parsing configuration/hibernate.cfg.xml" Watch "Getting error -problem parsing configuration/hibernate.cfg.xml" New topic

Getting error -problem parsing configuration/hibernate.cfg.xml

Abhra Kar
Ranch Hand

Joined: May 22, 2008
Posts: 150
Hi ,
I am new in hibernate.I am trying deploy a project and getting an error --
"problem parsing configuration/hibernate.cfg.xml
Exception in thread "main" java.lang.NullPointerException
at FirstExample.main("

Development steps:-
1> Install mySql at "C:\Program Files\MySQL\MySQL Server 5.0" [provide password "abhra" when installed]
create new database with command mysql> create database hibernatetutorial ;
and use it with mysql> use hibernatetutorial;
2> In eclipse create 2 .class and 2 xml files under src directory
public class Contact {
private String firstName;
private String lastName;
private String email;
private long id;

public String getEmail() {
return email;
public String getFirstName() {
return firstName;
public String getLastName() {
return lastName;
public void setEmail(String string) {
email = string;
public void setFirstName(String string) {
firstName = string;
public void setLastName(String string) {
lastName = string;
public long getId() {
return id;
public void setId(long l) {
id = l;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class FirstExample {
public static void main(String[] args){
Session session = null;
SessionFactory sessionFactory = new

System.out.println("Inserting Record");

Contact contact = new Contact();
}catch(Exception e){

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"

<class name="Contact" table="CONTACT">
<id name="id" type="long" column="ID">
<generator class="assigned" />

<property name="firstName">
<column name="FIRSTNAME" />

<property name="lastName">
<column name="LASTNAME" />

<property name="email">
<column name="EMAIL"/>


hibernate.cfg.xml ---
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"

<property name="connection.driver_class">

<proeprty name="connection.url">

<property name="connection.username">root</property>
<property name="connection.password">abhra</property>
<property name="connection.pool_size">10</property>

<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<property name="">update</property>

<mapping resource="contact.hbm.xml"/>


the <session-factory> tab is showing error--
" The content of session-factory must match (property*,mapping*,(class-cache|collection-cache)*,event*,listener*)"
I am not getting any idea what is happening here.
Please help me to solve the error.

Anjali Lamba

Joined: Feb 02, 2011
Posts: 11

Correct property spelling for name="connection.url"
Abhra Kar
Ranch Hand

Joined: May 22, 2008
Posts: 150
Thanks a lot , it's working now
I agree. Here's the link:
subject: Getting error -problem parsing configuration/hibernate.cfg.xml
jQuery in Action, 3rd edition