-->
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: Null Pointer Exception when calling a MSSQL Store Procedure
PostPosted: Wed Sep 24, 2008 3:31 pm 
Newbie

Joined: Thu Jun 26, 2008 5:13 pm
Posts: 5
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3,DataBase :MSSql 2000

Mapping documents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping auto-import="true" default-lazy="false">

<class name="com.ussco.persistence.supplychain.sqlserver.model.ConsCartonId">
<id name="cartonId" type="java.lang.String" column="CTN_ID" table="CARTON_ID">
</id>
<property name="facilityNum" type="java.lang.String" column="FAC_NUM" />
<property name="dayOfYear" type="java.lang.String" column="DAY_OF_YEAR" />
<property name="lastUpdate" type="java.util.Date" column="LAST_UPDATE" />
<loader query-ref="ConsCartonId.findProcedure" />
</class>
<sql-query name="ConsCartonId.findProcedure" callable="true">
<return alias="consoilated"
class="com.ussco.persistence.supplychain.sqlserver.model.ConsCartonId">
<return-property name="facilityNum" column="FAC_NUM"/>
<return-property name="dayOfYear" column="DAY_OF_YEAR" />
<return-property name="cartonId" column="CTN_ID" />
</return>
<query-param name="facilityNum" type="java.lang.String"></query-param>
<query-param name="dayOfYear" type="java.lang.String"></query-param>
<query-param name="cartonId" type="java.lang.String"></query-param>
{call myProcedure(:facilityNum,:dayOfYear,:cartonId)}
</sql-query>

</hibernate-mapping>



[b]MsSql Store Procedure :

ALTER procedure myProcedure

/* defined parameters */
@Fac char(2) out,
@DayOfYear char(3) out,
@ctn_id char(7) out /* next carton id */

as

declare @chctn char(7)
declare @intctn int
declare @rowcnt int
declare @error int

BEGIN TRAN

select @chctn = ctn_id /* does carton for specified facility & current date exists? */
from carton_id
where fac_num = @Fac
and day_of_year = @DayOfYear

select @rowcnt = @@rowcount, @error = @@error

IF (@error <> 0)
begin

ROLLBACK TRAN
RETURN(@ERROR)
end

if (@rowcnt > 0) /* if exists, then increment carton id */
BEGIN

select @intctn = ( convert(int, @chctn) + 1 )

update carton_id
set ctn_id = convert(char(7), @intctn ) ,
last_update = getdate( )
where fac_num = @Fac
and day_of_year = @DayOfYear

select @error = @@error
IF (@error <> 0)
begin
ROLLBACK TRAN
RETURN(@ERROR)
end
ELSE
begin
select @ctn_id = convert( char(7), @intctn )
COMMIT TRAN
end
END

else begin /* otherwise, insert 'first of day' carton id default '9000001' */
insert into carton_id values(@Fac, @DayOfYear, '9000001', getdate( ) )

select @error = @@error
IF (@error <> 0)
begin
ROLLBACK TRAN
RETURN(@ERROR)
end
ELSE
begin
select @ctn_id = '9000001'
COMMIT TRAN
end

end

return(@error) /* return value: SUCCESS | FAILURE */
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO



Query consCartons = this.getSession().getNamedQuery("ConsCartonId.findProcedure");
consCartons.setString("facilityNum", facNumber);
consCartons.setString("dayOfYear", dayOfYear);
consCartons.setString("cartonId", cartonId);
List cartons= consCartons.list();//throwing null pointer Exception here
Iterator iter=cartons.iterator();
while (iter.hasNext()) {
consCartonId = (ConsCartonId) iter.next();
System.out.println("id :"+consCartonId.getCartonId());
System.out.println("facNumber :"+consCartonId.getFacilityNum());
System.out.println("dayOfYear :"+consCartonId.getDayOfYear());
}



Full stack trace of any exception that occurs:

java.lang.NullPointerException
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
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.ussco.supplychain.cts.businessservice.impl.SampleProcedure.executeProcedure(SampleProcedure.java:17)
at com.ussco.supplychain.cts.view.bean.OrderBean.consolidatedCarton(OrderBean.java:1132)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:615)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:127)




Can anyone please tell where i am going wrong.Can this procedure be executed using hibernate.Is the hbm file sql-query return values match with that of the procedure.When my procedure was run on sql server 2000 which is taking input as 01 for facnumber,126 as dayof year and carton id as 9345553 it is printing lines with the facnumber,dayofyear,cartonid respectively.How can i acheive the same when i call from java program using named query.It would be great help if any one can help on this.[quote][/quote]


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.