Forums Register Login

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

+Pie Number of slices to send: Send
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(FirstExample.java:31)"



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
3> Contact.java--

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;
}
}



FirstExample.java


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;
try{
SessionFactory sessionFactory = new
Configuration().configure().buildSessionFactory();

session=sessionFactory.openSession();
System.out.println("Inserting Record");

Contact contact = new Contact();
contact.setId(3);
contact.setFirstName("Abhra");
contact.setLastName("Kar");
contact.setEmail("karabhra83@gmail.com");
session.save(contact);
System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
session.flush();
session.close();
}
}
}



contact.hbm.xml---

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

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

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

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

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

</class>
</hibernate-mapping>



hibernate.cfg.xml ---

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>

<session-factory>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>

<proeprty name="connection.url">
jdbc:mysql://localhost/hibernatetutorial
</proeprty>

<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="hbm2ddl.auto">update</property>

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

</session-factory>
</hibernate-configuration>



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.

Thanks
+Pie Number of slices to send: Send
Correct property spelling for name="connection.url"
+Pie Number of slices to send: Send
Thanks a lot , it's working now
I claim this furniture in the name of The Ottoman Empire! You can keep this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 917 times.
Similar Threads
data insert error
session.flush(); gives null
Data getting saved in session, but not being persisted in table.
Cannot insert record into Database!
NullPointerException in hibernate
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 09:32:21.