-->
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.  [ 2 posts ] 
Author Message
 Post subject: SessionFactory returning null
PostPosted: Wed Nov 25, 2009 8:40 am 
Newbie

Joined: Wed Nov 25, 2009 8:15 am
Posts: 1
Hi all,

I am new in Hibernate. I am getting sessionfactory object as null. But the configuration in hibernate.cfg.xml file seems to be ok.
Code:
<hibernate-configuration>
<session-factory>
      <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
      <property name="hibernate.connection.url">jdbc:oracle:thin:@10.1.1.1:1521:test</property>
      <property name="hibernate.connection.username">ORV5_ETL_ZAIN_KSA_D2</property>
      <property name="hibernate.connection.password">ORV5_ETL_ZAIN_KSA_D2</property>
      <property name="hibernate.connection.pool_size">10</property>
      <property name="show_sql">true</property>
      <property name="dialect">org.hibernate.dialect.OracleDialect</property>
      <property name="hibernate.hbm2ddl.auto">update</property>
      <!-- Mapping files -->
      <mapping resource="contact.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Code:
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(new   Configuration().configure().buildSessionFactory());
         SessionFactory sessionFactory = new   Configuration().configure().buildSessionFactory();
         session = sessionFactory.openSession();
         System.out.println("se->"+session);
         // 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("Deepak");
         contact.setLastName("Kumar");
         contact.setEmail("deepak_38@yahoo.com");
         session.save(contact);
         System.out.println("Done");
      } catch (Exception e) {
         e.printStackTrace();
         //System.out.println(e.getMessage());
      } finally {
         // Actual contact insertion will happen at this step
         session.flush();
         session.close();
   
      }
   
   }
}

INFO: building session factory
Exception in thread "main" java.lang.NullPointerException
at com.hibernate.test.FirstExample.main(FirstExample.java:38)


Actually when the information is showing in the console , there also the information is showing as 'INFO: Configured SessionFactory: null'.

Please help.

Thanks & regards,
Kousik


Last edited by Kousik on Thu Nov 26, 2009 2:58 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: SessionFactory returning null
PostPosted: Thu Nov 26, 2009 2:18 am 
Newbie

Joined: Thu Nov 26, 2009 2:05 am
Posts: 5
Kousik wrote:
Hi all,

I am new in Hibernate. I am getting sessionfactory object as null. But the configuration in hibernate.cfg.xml file seems to be ok.
Code:
<hibernate-configuration>
<session-factory>
      <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
      <property name="hibernate.connection.url">jdbc:oracle:thin:@10.1.1.1:1521:test</property>
      <property name="hibernate.connection.username">ORV5_ETL_ZAIN_KSA_D2</property>
      <property name="hibernate.connection.password">ORV5_ETL_ZAIN_KSA_D2</property>
      <property name="hibernate.connection.pool_size">10</property>
      <property name="show_sql">true</property>
      <property name="dialect">org.hibernate.dialect.OracleDialect</property>
      <property name="hibernate.hbm2ddl.auto">update</property>
      <!-- Mapping files -->
      <mapping resource="contact.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Please help.

Thanks & regards,
Kousik


Can you describe your question more..? These information not enough... better you can post stack race and where this was happened...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.