-->
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.  [ 1 post ] 
Author Message
 Post subject: java.lang.NullPointerException at org.hibernate.load
PostPosted: Thu Aug 18, 2011 5:10 am 
Newbie

Joined: Thu Aug 18, 2011 5:05 am
Posts: 1
hi my hibernate mapping is
<?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.Stock" table="reg">
<id name="stockId" type="java.lang.Integer">
<column name="STOCKid" />
<generator class="identity" />
</id>
<property name="stockCode">
<column name="STOCK"/>
</property>
</class>

<sql-query name="sp_GetData" callable="true" >
<return class="com.Stock">
<return-property name="stockId" column="STOCKid"/>
<return-property name="stockCode" column="STOCK"/>
</return>

{ call myGetdata(?,?) }

</sql-query>

</hibernate-mapping>


and my main program is


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com;

import java.util.List;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class hibernate {


public static void main(String args[]) throws IllegalStateException, SystemException {
Session session = null;
System.out.println("I am inside LoginDao class");
Transaction tx = null;



try {
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
Query qry = session.getNamedQuery("sp_GetData");
System.out.println("to insert the records");
qry.setString(0,"1");
qry.setString(1, "fgfspog");

List list = qry.list();

System.out.println("dfgfd"+list.size());
session.clear();




// Stock stock=new Stock();
// String id=stock.getStockCode();
// int code=stock.getStockId();
//session = sessionFactory.openSession();
//System.out.print("******************");
//Query query = session.getNamedQuery("query");

// int value = query.executeUpdate();
//System.out.print(query);
//query.setInteger(0, 11);
//query.setString(1, "id");
//query.executeUpdate();



/*for(Iterator it = query.iterate();it.hasNext();)
{
String name=(String) it.next();
System.out.print("******************");
System.out.print(name);
} */
} catch (Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}finally
{
// Actual contact insertion will happen at this step
session.flush();
session.close();

}
}
}


but it is showing the following Exception When we run it


INFO: schema update complete
to insert the records
Hibernate: { call myGetdata(?,?) }
java.lang.NullPointerException
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
null
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
at com.hibernate.main(hibernate.java:33)
Plz help me...............thanks in Advance


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

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.