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

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

Abhra Kar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct property spelling for name="connection.url"
Abhra Kar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot , it's working now
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!