Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2009
    Posts
    21
    Rep Power
    0

    Default Hibernate aplication Problem

    hi,
    I am new in Hibernate I am developing simple application using Hibernate when I am trying to run my code I am facingn such error


    10 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
    12 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
    15 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
    19 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
    77 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
    77 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
    152 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
    157 [main] INFO org.hibernate.connection.DriverManagerConnectionPr ovider - Using Hibernate built-in connection pool (not for production use!)
    157 [main] INFO org.hibernate.connection.DriverManagerConnectionPr ovider - Hibernate connection pool size: 20
    157 [main] INFO org.hibernate.connection.DriverManagerConnectionPr ovider - autocommit mode: false
    164 [main] INFO org.hibernate.connection.DriverManagerConnectionPr ovider - using driver: net.sourceforge.jtds.jdbc.Driver at URL: jdbc:jtds:sqlserver://MATRIX:1433//NewTest;instance=NEO
    164 [main] INFO org.hibernate.connection.DriverManagerConnectionPr ovider - connection properties: {user=Neo, password=****}
    275 [main] INFO org.hibernate.cfg.SettingsFactory - RDBMS: Microsoft SQL Server, version: 10.00.1600
    275 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: jTDS Type 4 JDBC Driver for MS SQL Server and Sybase, version: 1.2
    297 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.SQLServerDialect
    330 [main] INFO org.hibernate.transaction.TransactionFactoryFactor y - Using default transaction strategy (direct JDBC transactions)
    331 [main] INFO org.hibernate.transaction.TransactionManagerLookup Factory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    331 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
    331 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
    332 [main] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
    332 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
    332 [main] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
    332 [main] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
    332 [main] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
    332 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
    332 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
    332 [main] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    334 [main] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
    334 [main] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
    334 [main] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
    334 [main] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
    334 [main] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
    334 [main] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
    334 [main] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
    334 [main] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
    337 [main] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
    337 [main] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
    337 [main] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
    337 [main] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
    370 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
    372 [main] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
    Error Occured
    Exception in thread "main" java.lang.NullPointerException
    at com.vaannila.util.Main.saveCource(Main.java:42)
    at com.vaannila.util.Main.main(Main.java:15)

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    Something on line 42 of Main is null.

  3. #3
    tenderuser is offline Member
    Join Date
    Aug 2009
    Posts
    4
    Rep Power
    0

    Default

    can you post your code here ? how you get your sessionFactory Object ? there maybe some errors in your configure file of hibernate

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    I suspect it is a pure and simple case of something on line 42 being null.

  5. #5
    Join Date
    Aug 2009
    Posts
    21
    Rep Power
    0

    Default

    Quote Originally Posted by tenderuser View Post
    can you post your code here ? how you get your sessionFactory Object ? there maybe some errors in your configure file of hibernate
    here is my Session Factory Class


    package com.vaannila.util;


    import org.hibernate.SessionFactory;

    import org.hibernate.cfg.Configuration;



    public class HibernateUtil {

    private static final SessionFactory sessionFactory;

    static {

    try {

    sessionFactory = new Configuration().configure()

    .buildSessionFactory();

    } catch (Throwable ex) {

    System.err.println("Initial SessionFactory creation failed." + ex);

    throw new ExceptionInInitializerError(ex);

    }

    }



    public static SessionFactory getSessionFactory() {

    return sessionFactory;

    }

    }

  6. #6
    Join Date
    Aug 2009
    Posts
    21
    Rep Power
    0

    Default

    Quote Originally Posted by Prashant.surwade View Post
    here is my Session Factory Class


    package com.vaannila.util;


    import org.hibernate.SessionFactory;

    import org.hibernate.cfg.Configuration;



    public class HibernateUtil {

    private static final SessionFactory sessionFactory;

    static {

    try {

    sessionFactory = new Configuration().configure()

    .buildSessionFactory();

    } catch (Throwable ex) {

    System.err.println("Initial SessionFactory creation failed." + ex);

    throw new ExceptionInInitializerError(ex);

    }

    }



    public static SessionFactory getSessionFactory() {

    return sessionFactory;

    }

    }
    here is Model means data is encapsulates in that class


    package com.vaannila.util;

    import java.util.Iterator;
    import java.util.List;

    import org.hibernate.classic.Session;

    import com.vannila.cource.Cource;
    import com.vaannila.util.HibernateUtil;
    public class Main {
    public static void main(String args[])
    {

    Main obj = new Main();
    Long courseId1 = obj.saveCource("Physics");
    Long courseId2 = obj.saveCource("Chemistry");
    Long courseId3 = obj.saveCource("Maths");
    obj.ListCource();

    }
    public long saveCource(String cource)
    {
    Session session=HibernateUtil.getSessionFactory().openSess ion();
    org.hibernate.Transaction tr=null;
    Long courseId = null;
    try
    {
    tr=session.beginTransaction();

    Cource cr=new Cource();
    cr.setCourceName(cource);
    courseId=(Long)session.save(cr);
    tr.commit();


    }catch(Exception e)
    {
    System.out.println("Error Occured");
    tr.rollback();

    }
    return courseId;
    }

    public void ListCource()
    {
    Session session=HibernateUtil.getSessionFactory().openSess ion();

    org.hibernate.Transaction tr=null;
    try
    {
    List list=session.createQuery("from COURCES").list();

    Iterator it=list.iterator();
    while(it.hasNext())
    {
    Cource cr=(Cource)it.next();
    System.out.println(cr.getCourceName());
    }



    }catch(Exception e)
    {
    e.printStackTrace();
    }

    }


    }

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

Similar Threads

  1. composite-id problem hibernate
    By javadev in forum JDBC
    Replies: 14
    Last Post: 07-27-2009, 06:30 PM
  2. Hibernate cache problem
    By jispat in forum New To Java
    Replies: 0
    Last Post: 12-29-2008, 11:18 AM
  3. problem in hibernate need help!
    By jrgahan in forum Advanced Java
    Replies: 0
    Last Post: 05-22-2008, 09:00 AM
  4. Problem with First Hibernate program
    By sireesha in forum JDBC
    Replies: 11
    Last Post: 05-05-2008, 04:19 PM
  5. problem with hibernate and oracle 8i
    By javadev in forum JDBC
    Replies: 4
    Last Post: 08-09-2007, 02:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •