-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 
Author Message
 Post subject: NewUser: sessionFactory is not getting created
PostPosted: Tue Aug 01, 2006 5:07 am 
Beginner
Beginner

Joined: Tue Aug 01, 2006 4:57 am
Posts: 25
Hi
I am a new user of Hibernate and I need some help.
This is the code:
Code:
package com.rosenet.pojo;

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{
       
       // This step will read hibernate.cfg.xml and prepare hibernate for use

        System.out.println("I am here");
       SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
       session = sessionFactory.openSession();
       
       //Create new instance of Contact and set values in it by reading them from form object

        System.out.println("Inserting Record");
        Contact contact = new Contact();
        contact.setId(3);
        contact.setFirstName("Riaz");
        contact.setLastName("Uddin");
        contact.setEmail("ruuddin@yahoo.com");
       
        session.save(contact);
       
       
        System.out.println("Done");
       
    }catch(Exception e){
      System.out.println(e.getMessage());
    }finally{
      // Actual contact insertion will happen at this step
      session.flush();
      session.close();

      }
  }
}

When i run this program in eclipse it shows Nullpointer exception at session.flush();
When i tried to debug I found that the session factory is not getting created.
the hibernate.cfg.xml file is as follows:
Code:
<?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="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/samepageinfosol</property>
      <property name="hibernate.connection.username">localhost</property>
      <property name="hibernate.connection.password"></property>
      <property name="hibernate.connection.pool_size">10</property>
      <property name="show_sql">true</property>
      <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
   <property name="hibernate.hbm2ddl.auto">update</property>
      <!-- Mapping files -->
      <mapping resource="contact.hbm.xml"/>
</session-factory>
</hibernate-configuration>


I have placed this file in WEB-INF/ folder and my contact.hbm.xml file is as follows:
Code:
<?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="com.rosenet.pojo.Contact" table="contact">
   <id name="id" type="long" column="id" >
   <generator class="assigned"/>
  </id>

  <property name="firstName">
     <column name="first_name" />
  </property>
  <property name="lastName">
    <column name="last_name"/>
  </property>
  <property name="email">
    <column name="email"/>
  </property>
</class>
</hibernate-mapping>


What is wrong with this code... ? can someone help..


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 01, 2006 5:09 am 
Beginner
Beginner

Joined: Tue Aug 01, 2006 4:57 am
Posts: 25
I am sorry, this was because of the bad connection


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 01, 2006 6:22 am 
Beginner
Beginner

Joined: Tue Aug 01, 2006 4:57 am
Posts: 25
can someone please help


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 01, 2006 6:32 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
Get rid of the catch section and post the message on the eclipse console.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 01, 2006 6:58 am 
Beginner
Beginner

Joined: Tue Aug 01, 2006 4:57 am
Posts: 25
how can i print the message if i remove the catch expression, there will be no exception caught... hence no message... correct me if i am wrong


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 01, 2006 7:16 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
It will be printed in the console.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 01, 2006 3:39 pm 
Beginner
Beginner

Joined: Tue Aug 01, 2006 4:57 am
Posts: 25
I removed the catch block and the exception is now getting printed on console and it is the same nullpointer exception.... occuring at seesion.flush(); statement. What cna be done??


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 01, 2006 4:22 pm 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
post the full message.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 01, 2006 4:57 pm 
Beginner
Beginner

Joined: Tue Aug 01, 2006 4:57 am
Posts: 25
it says
java.lang.NullpointerException
when i clicked on it, it went to session.flush().

After that i made few more modifications, I removed the catch block and commented the statements in finally block....

That displayed the error as NoClassDefFoundError: LoadFactory

I search for it on internet and then i downloaded the jar files: all the commons-logging jar files...

In the next run, it displayed NoClassDefFoundError: SequencedHashMap

I search for it on internet again and i got the jar file: commons-collections.jar

I run again i get the NoClassDefFoundError: "it was about some cache, cant recall" then i get another jar file ehcache.jar... and still i keep getting errors... i realised that I am missing something for sure...
But dont know... Please help...it is driving me crazy....

May be the versions are new:
Hibernate3
Eclipse3.2


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 01, 2006 5:01 pm 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
There is a lib directory in the hibernate.zip archive.
You can copy all the jar files from it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 01, 2006 5:05 pm 
Beginner
Beginner

Joined: Tue Aug 01, 2006 4:57 am
Posts: 25
hey finally solved the problem....
i removed the jar files from the build path and added them again....i dont know how it managed to work this time....

Thanks for your continuous help


Top
 Profile  
 
 Post subject: Re: NewUser: sessionFactory is not getting created
PostPosted: Wed Aug 02, 2006 1:00 am 
Newbie

Joined: Wed Jul 26, 2006 5:19 am
Posts: 3
HI,
This is balaji. i got the same error wt u r getting.but i cant able to resolve the issue till now. i am just trying this one for past 2 days.can u pls help me regarding this one.can pls send me snapshots of eclipse where to place the all the files .

i will be very thankfull to u if u help me.

my emailid is balaji_a_u@yahoo.co.in

waiting for u r reply .


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.