-->
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.  [ 4 posts ] 
Author Message
 Post subject: CreateQuery Session Closed!
PostPosted: Sun Sep 03, 2006 5:48 am 
Newbie

Joined: Tue Mar 21, 2006 1:29 pm
Posts: 9
Hi,

I got a session closed while trying to retreive the getResultList() during my unit test;

I using Hibernate core 3.2 CR2 and Hibernate EntityManager 3.2.0 CR1 and Hibernate Annotations 3.2.0 CR1.

Here is the code

Code:
package entity.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

public class ColorDAOImpl implements ColorDAO {

    private EntityManager em;

    @PersistenceContext
    public void setEntityManager(EntityManager em) {
        this.em = em;
    }

    public List getList() {
        Query query = em.createQuery("from Color");
        List list = query.getResultList();
        System.out.println("List"+list.size());
        return list;
   }

}


here is the stacktrace


javax.persistence.PersistenceException: org.hibernate.SessionException: Session is closed!
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:567)
at org.hibernate.ejb.QueryImpl.getResultListQueryImpl.java:56)
at com.itdove.gems.entity.dao.ColorDAOImpl.getListColorDAOImpl.java:22)
at com.itdove.gems.entity.dao.TestColorDAO.testGetListTestColorDAO.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
at sun.reflect.NativeMethodAccessorImpl.invokeUnknownSource)
at sun.reflect.DelegatingMethodAccessorImpl.invokeUnknownSource)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtectedTestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:228)
at junit.framework.TestSuite.run(TestSuite.java:223)
at org.junit.internal.runners.OldTestClassRunner.runOldTestClassRunner.java:35)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.hibernate.SessionException: Session is closed!
at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:49)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1103)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:53)
... 21 more

I using spring jpa integration the generate the EntityManager. May be I totally wrong, but any body could help me?

Thanks
Dominique


Top
 Profile  
 
 Post subject: Re: CreateQuery Session Closed!
PostPosted: Fri Sep 08, 2006 9:50 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
vernid wrote:
I using spring jpa integration the generate the EntityManager. May be I totally wrong, but any body could help me?


More of a Spring forum question then - why Spring 'serves' you a closed session?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 08, 2006 8:12 pm 
Senior
Senior

Joined: Sat Nov 27, 2004 4:13 am
Posts: 137
but there is nothing of Spring in the stacktrace!

_________________
don't forget to credit!

Amir Pashazadeh
Payeshgaran MT
پايشگران مديريت طرح
http://www.payeshgaran.co
http://www.payeshgaran.org
http://www.payeshgaran.net


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 11, 2006 8:37 am 
Beginner
Beginner

Joined: Sat Oct 08, 2005 2:13 am
Posts: 47
Hi

I think you should get the session from Spring. because this is the Spring that manages the sessions and beans.

but may be you should use something like this:

Code:
em.getSession().createQuery()....


Regards
Mohammad Norouzi


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