-->
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.  [ 5 posts ] 
Author Message
 Post subject: Getting java.lang.NullPointerException
PostPosted: Thu Jun 22, 2006 3:26 pm 
Newbie

Joined: Thu Jun 22, 2006 3:10 pm
Posts: 3
Am using Hibernate 3.1.3 with Spring 1.2.8

Have been getting java.lang.NullPointerException when I make a call to getHibernateTemplate().load(User.class,username) . So in order to make sure that I'm getting HibernateTemplate I changed my method call to
HibernateTemplate ht = getHibernateTemplate() ;
User user = ht.load(User.class,username)....put a watch on ht to check if it null, but its not. I'm running out of ideas here. please advise somebody else faced the same problem

Here is my Hibernate.cfg.xml file

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<mapping resource="nagtier1spring/model/businessobject/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Here is my method from Dao.....
public User getUser(String username) {
User user = null ;
try {
HibernateTemplate ht = getHibernateTemplate() ;
user = (User)ht.load(User.class,username) ;
}catch(Exception e) {
System.out.println(e.toString());
}
return user;
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 3:38 pm 
Newbie

Joined: Thu Jun 22, 2006 3:10 pm
Posts: 3
Here is the stacktrace.....................

java.lang.NullPointerException
at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3121)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:232)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:173)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:781)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:774)
at org.springframework.orm.hibernate3.HibernateTemplate$3.doInHibernate(HibernateTemplate.java:490)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
at org.springframework.orm.hibernate3.HibernateTemplate.load(HibernateTemplate.java:484)
at org.springframework.orm.hibernate3.HibernateTemplate.load(HibernateTemplate.java:478)
at nagtier1spring.model.dao.hibernate.UserDaoHibernateImpl.getUser(UserDaoHibernateImpl.java:41)
at nagtier1spring.model.service.impl.UserServiceImpl.login(UserServiceImpl.java:39)
at nagtier1spring.view.bean.UserBean.loginAction(UserBean.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
at javax.faces.component.UICommand.broadcast(UICommand.java:312)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:225)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:127)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:272)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3151)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:1973)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1880)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1310)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:207)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:179)


Top
 Profile  
 
 Post subject: I think
PostPosted: Thu Jun 22, 2006 7:03 pm 
Regular
Regular

Joined: Wed Feb 22, 2006 11:28 am
Posts: 65
Location: Santiago, Chile
Change load to get.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 23, 2006 8:52 am 
Newbie

Joined: Thu Jun 22, 2006 3:10 pm
Posts: 3
Thank you, get works, by any chance do you know why load would'nt work ?


Top
 Profile  
 
 Post subject: I think
PostPosted: Fri Jun 23, 2006 9:46 am 
Regular
Regular

Joined: Wed Feb 22, 2006 11:28 am
Posts: 65
Location: Santiago, Chile
Hello Friend:

I saw you have used Spring Framework with Hibernate, I am too. When you don´t specify explicitly in your assotiation collections "lazy=false", Spring should throws you a "NullPointerException" for initializing the lazy entities or collections.

I still research how can we sovle this problem without change the code as I posted you.

I think, you may used hibernateTemplate to load a entity by a key. You can get a "Session" opened from hibernateTemplate to do it again, I guess that wouldn´t throws you a exception.

Spring manage by itself the session. You should read in more detail about session in view pattern.

Regards.


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