-->
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 Exc when trying to getSession().get(class, Id)
PostPosted: Mon Mar 21, 2005 3:12 pm 
Newbie

Joined: Mon Mar 21, 2005 3:03 pm
Posts: 1
Hi,

I would appreciate any advice regarding the following issue.

We are using Webworks +Hibernate (2.1.4) with MySQL (4.1)

I am getting a NULL POINTER Exception while trying to do getSession(classname, id).

Thanks,
MK

==============================================
Here are my Database Schema to save this search criterias:
==============================================

SavedSearchMaster
-----------------
SS_Id Int NOT NULL AUTO_INCREMENT, PRIMARY KEY
SavedSearch_Name Varchar(60)
User_Id Int Foreign Key
Created_Date Date
Updated_Date Date


UserTable
---------
User_Id Int (PK)
Username Varchar(40)


Relation between UserTable --------------> SavedSearchMaster
(one) (Many)

==============================================
Hibernate Mapping files
==============================================

UserTable.hbm.xml
------------------

<hibernate-mapping>
<class
name="com.heartbeat.profiler.model.UserTable"
table="user_table"
>
<id
name="userId"
type="java.lang.Integer"
column="User_Id"
>
<generator class="native" />
</id>

<property
name="username"
type="java.lang.String"
column="Username"
length="50"
/>

<set name="savedSearchMaster" table="SAVEDSEARCH_MASTER" inverse="true" lazy="true">
<key column="user_id"/>
<one-to-many class="com.heartbeat.profiler.model.SavedSearchMaster"/>
</set>

</class>
</hibernate-mapping>

SavedSearchMaster.hbm.xml
-------------------------

<hibernate-mapping>
<class
name="com.heartbeat.profiler.model.SavedSearchMaster"
table="SavedSearch_Master"
>

<id
name="ssId"
type="java.lang.Integer"
column="SS_Id"
>
<generator class="native" />
</id>

<property
name="savedSearchName"
type="java.lang.String"
column="SavedSearch_Name"
length="60"
/>

<property
name="userId"
type="java.lang.Integer"
column="User_Id"
/>

<property
name="createdDate"
type="java.sql.Date"
column="Created_Date"
/>

<property
name="updatedDate"
type="java.sql.Date"
column="Updated_Date"
/>

<!-- associations -->
<many-to-one name="userTable" column="user_id" class="com.heartbeat.profiler.model.UserTable"/>

</class>
</hibernate-mapping>

==============================================
in Action class
==============================================

// Get searchBean from session
searchBean = (SearchBean)get("searchBean");
// Get userId from session
userId = (Integer)get("userId");

NULL ==> userTable = (UserTable) getSession().get(UserTable.class, userId);

set("userTable", userTable);
set("savedSearchMaster", savedSearchMaster);

savedSearchMaster.setSavedSearchName(searchBean.getSearchName());
savedSearchMaster.setUserTable(userTable);
getSession().save(savedSearchMaster);
getSession().flush();

==============================================
ERROR I AM GETTING IS
==============================================
java.lang.NullPointerException
at com.heartbeat.profiler.action.AbstractAction.getSession(AbstractAction.java:70)
at com.heartbeat.profiler.action.SavedSearchDelegateAction.go(SavedSearchDelegateAction.java:55)
at com.heartbeat.profiler.action.AbstractAction.execute(AbstractAction.java:51)
at com.heartbeat.profiler.action.SavedSearchAction.go(SavedSearchAction.java:63)
at com.heartbeat.profiler.action.AbstractAction.execute(AbstractAction.java:51)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:168)
at com.heartbeat.profiler.interceptor.HibernateInterceptor.intercept(HibernateInterceptor.java:32)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
at com.heartbeat.profiler.interceptor.AuthorizeInterceptor.intercept(AuthorizeInterceptor.java:65)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)


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.