-->
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.  [ 3 posts ] 
Author Message
 Post subject: LazyInitializationException with select count(*) from table
PostPosted: Sun Oct 01, 2006 1:34 pm 
Beginner
Beginner

Joined: Sun Feb 12, 2006 12:19 am
Posts: 20
I can't seem to successfully execut a select count(*) from a table.
Should be simple I'm using the Spring classes and can retrieve records elsewhere but am getting exceptions doing a select count(*) and getting and Integer back (I want to get 0 when the table is empty too). The spring HibernateDaoSupport is a little different than the examples in the Hibernate manual since you're not dealling directly with the session.

Can Somebody help me?


Hibernate version:
3.1

Mapping documents:
Quote:
<hibernate-mapping>
<class name="com.age.j.soft.hibernate.UsersBean"
table="users">
<id name="username">
<generator class="native"/>
</id>
<property name="password"/>
<property name="read" type="boolean"/>
<property name="write" type="boolean"/>
<property name="edit" type="boolean"/>
<property name="delete" type="boolean"/>
<property name="email" column="email"/>
<property name="lastAccessDate" column="last_access_date" type="timestamp"/>
<property name="active" type="boolean"/>
</class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
Code:

UsersDAO extends HibernateDaoSupport

public int getNumUsers()
   {
      HibernateTemplate template = this.getHibernateTemplate();
      
      List list = template.find("select count(*) as n from " + UsersBean.class.getName());
      
      Integer integer = (Integer)list.get(0);
      Hibernate.initialize(integer);
      return integer.intValue();
   }



Full stack trace of any exception that occurs:
10/01/2006 12:22:13 ERROR org.hibernate.LazyInitializationException.http-8080-Processor25 - could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:56)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:98)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:158)
at com.age.j.soft.hibernate.UsersBean$$EnhancerByCGLIB$$39e0b73c.getPassword(<generated>)
at com.age.j.soft.action.LoginAction.execute(LoginAction.java:46)
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.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:334)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:195)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:170)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:193)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:115)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:193)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:193)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.intercept(ParametersInterceptor.java:118)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:193)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:193)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:204)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:193)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:193)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:115)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:193)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:143)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:193)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.intercept(PrepareInterceptor.java:115)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:193)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:155)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:193)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.intercept(ParametersInterceptor.java:118)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:193)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:123)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:193)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:180)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:193)
at org.apache.struts2.impl.StrutsActionProxy$1.call(StrutsActionProxy.java:25)
at org.apache.struts2.impl.StrutsActionProxy$1.call(StrutsActionProxy.java:24)
at org.apache.struts2.impl.RequestContextImpl.callInContext(RequestContextImpl.java:147)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:23)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:317)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:242)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)



Name and version of the database you are using:
MySQL 4


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 01, 2006 5:24 pm 
Regular
Regular

Joined: Tue Sep 26, 2006 11:37 am
Posts: 115
Location: Sacramento, CA
I am not sure why you get that exception, however you may want to see example of HQL count(*) over here

http://www.hibernate.org/hib_docs/v3/re ... ggregation

You may want to try removing 'as n' to start with.. I hope this helps :)

Marius


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 01, 2006 5:44 pm 
Beginner
Beginner

Joined: Sun Feb 12, 2006 12:19 am
Posts: 20
That doesn't really help me. That is the same as in the PDF manual I was looking at.


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