Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Frameworks
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Other Application Frameworks
Unable to run the Hibernate program
Arun chandu
Greenhorn
Posts: 15
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello Everyone,
I'm learning Hibernate. I search lot of site for ref. when ever i trying to run the program, it showing error.
I'm using Eclipse for the programming and add all jar file into library through buildpath. Here the code for the ManageEmployee
package com.pack; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder; public class ManageEmployee { private static SessionFactory sessionFactory; private static ServiceRegistry serviceRegistry; public static void main(String[] args) { Session session = null; try { try { Configuration cfg = new Configuration().addResource("Employee.hbm.xml").configure(); serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry(); sessionFactory = cfg.buildSessionFactory(); } catch (Throwable ex) { System.err.println("Failed to create sessionFactory object."+ ex); throw new ExceptionInInitializerError(ex); } session = sessionFactory.openSession(); Employee emp = new Employee(); System.out.println("Inserting Record"); Transaction tx = session.beginTransaction(); emp.setId(1); emp.setFirstName("Arun"); emp.setLastName("chandu"); emp.setSalary(15000); session.save(emp); tx.commit(); } catch (Exception e) { System.out.println(e.getMessage()); } finally { session.close(); } } }
Here its is POJO class
package com.pack; public class Employee { private int id; private String firstName; private String lastName; private int salary; public Employee(){} public Employee(int id, String firstName, String lastName, int salary) { this.id = id; this.firstName = firstName; this.lastName = lastName; this.salary = salary; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public int getSalary() { return salary; } public void setSalary(int salary) { this.salary = salary; } }
and conf. file is here:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <!-- Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration> <session-factory> <!-- Data base connection --> <property name="hibernate.dialect"> org.hibernate.dialect.MYSQLDialect </property> <property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver </property> <!-- Database URL --> <property name="hibernate.connection.url"> jdbc:mysql://localhost/test </property> <!-- Database username and password --> <property name="hibernate.connection.username">root</property> <property name="hibernaet.connection.password">root</property> <property name="show_sql">true</property> </session-factory> <!-- List of XML mapping files --> <mapping resource="Employee.hbm.xml"/> </hibernate-configuration>
Even every i'm running the program then its shows
log4j:WARN No appenders could be found for logger (org.hibernate.type.BasicTypeRegistry). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. Failed to create sessionFactory object.org.hibernate.MappingException: invalid configuration Exception in thread "main" java.lang.NullPointerException at com.pack.ManageEmployee.main(ManageEmployee.java:40)
And im attaching the jar file image
Please help me.
Thanks in advance.
project.jpg
Project file with jar file
Hussein Baghdadi
clojure forum advocate
Posts: 3479
I like...
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I'm not a 'Hibernate' savvy but I guess that you need to specify also the port for
hibernate.connection.url
property.
Hussein Baghdadi
clojure forum advocate
Posts: 3479
I like...
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
And you have a typo here:
hibernaet.connection.password
Arun chandu
Greenhorn
Posts: 15
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thank Hussein Baghdadi for responding.
I corrected the 'hibernaet.connection.password' long back, even its not working.
Hussein Baghdadi
clojure forum advocate
Posts: 3479
I like...
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
What is the exception/error you are getting this time?
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
hibernate3 : help find out the error
org.hibernate.InvalidMappingException
java.lang.reflect.UndeclaredThrowableException
unable to insert data in mysql through hibernate even program run without error
/hibernate.cfg.xml not found while Running simple java program
More...