SessionException on simple request

732 views
Skip to first unread message

Torsten Zesch

unread,
Dec 4, 2012, 10:13:56 AM12/4/12
to uby-...@googlegroups.com
Hi,

I get a SessionException
Exception in thread "main" org.hibernate.SessionException: Session is closed!
    at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:72)
    at org.hibernate.impl.SessionImpl.getBatcher(SessionImpl.java:305)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
    at org.hibernate.loader.Loader.doQuery(Loader.java:802)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
    at org.hibernate.loader.Loader.loadCollection(Loader.java:2166)
    at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:62)
    at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:627)
    at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
    at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1863)
    at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:369)
    at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:111)
    at org.hibernate.collection.PersistentList.iterator(PersistentList.java:138)
    at test.uby.UbyTest.main(UbyTest.java:38)

when running the following code on Uby 0.2.0.
The line when this is thrown differs a bit, but usually is aroung 800 - 1500.

    public static void main(String[] args) throws Exception
    {
        DBConfig db = new DBConfig(
                "localhost/uby020",
                "com.mysql.jdbc.Driver",
                "mysql",
                USER,
                PW,
                true,
                false
        );
       
        Uby uby = new Uby(db);
       
        Lexicon lex = uby.getLexiconByName("WiktionaryEN");
       
        Iterator<LexicalEntry> lexIt = uby.getLexicalEntryIterator(null, lex);

        int i=0;
        while (lexIt.hasNext()) {
            LexicalEntry le =lexIt.next();
            for (Sense s: le.getSenses()) {
                for (Equivalent eq: s.getEquivalents()){
                    if (eq.getLanguageIdentifier().equals(ELanguageIdentifier.ISO639_SPA)){
                        i++;
                        System.out.println(i + "\t" + le.getLemmaForm()+"\t" + eq.getWrittenForm());
                    }
                }
            }
        }
    }

Do you have an idea what is going on?

-Torsten

Judith Eckle-Kohler

unread,
Dec 4, 2012, 12:43:16 PM12/4/12
to UBY Users
Hi Torsten,

my guess is that this error is related to the fact that the UBY-API
uses a modified Hibernate version; if you have the "normal" Hibernate
already in your local .m2 repository (e.g. for JWPL), it might be the
case that Maven uses the wrong Hibernate when building your test
project.
If you are experiencing this problem, but your colleagues who happen
not to have JWPL in their .m2 repository not, then this is another
indicator. I also do not have this problem and I currently do not use
JWPL.

Best
Judith

Torsten Zesch

unread,
Dec 11, 2012, 6:39:18 AM12/11/12
to uby-...@googlegroups.com, eckle....@googlemail.com
Hi Judith,

does this mean you have verified the above code works in your setting?

What do you mean with "modified" hibernate?
I have several hibernate versions in my .m2, but how should they influence Uby if they are not referenced in the project?

-Torsten

Richard Eckart de Castilho

unread,
Dec 11, 2012, 6:55:49 AM12/11/12
to uby-...@googlegroups.com, Judith Eckle-Kohler
Am 11.12.2012 um 12:39 schrieb Torsten Zesch <torste...@gmail.com>:

> What do you mean with "modified" hibernate?
> I have several hibernate versions in my .m2, but how should they influence Uby if they are not referenced in the project?

Uby currently uses a patched Hibernate with addresses some special issues in the Java<->DB mapping. It wouldn't be a bad idea to switch to an official Hibernate version.

Cheers,

-- Richard

Torsten Zesch

unread,
Dec 11, 2012, 8:32:39 AM12/11/12
to uby-...@googlegroups.com
Hi,

I do not want to switch to another version.
I just don't understand how my problem should be connected to other Hibernate version being located on my machine if they are not referenced by the Uby POM or my own POM?

-Torsten

2012/12/11 Richard Eckart de Castilho <richard...@googlemail.com>

Judith Eckle-Kohler

unread,
Dec 11, 2012, 11:02:17 AM12/11/12
to UBY Users
Hi Torsten,

now I reproduced the error, the full error message is pasted below;
I will add this to the issue list and for the time until someone
resolves this issue: do not use the getLexicalEntryIterator method
from the Uby-API.


25178 [main] WARN org.hibernate.jdbc.AbstractBatcher - exception
clearing maxRows/queryTimeout
java.sql.SQLException: You can't operate on a closed Statement!!!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:65)
at
com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.getMaxRows(NewProxyPreparedStatement.java:
1206)
at
org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:
298)
at
org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:
234)
at org.hibernate.loader.Loader.doQuery(Loader.java:854)
at syntax.LexEntryQueries.main(LexEntryQueries.java:48)
Caused by: java.lang.NullPointerException
at
com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.maybeDirtyTransaction(NewProxyPreparedStatement.java:
2069)
at
com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.getMaxRows(NewProxyPreparedStatement.java:
1198)
... 13 more
Exception in thread "main" org.hibernate.SessionException: Session is
closed!
at
org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:
72)
at
org.hibernate.impl.SessionImpl.getPersistenceContext(SessionImpl.java:
1954)
at
org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:
120)
at
org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:
982)
at org.hibernate.loader.Loader.doQuery(Loader.java:857)
at syntax.LexEntryQueries.main(LexEntryQueries.java:47)

See also Issue at Google Code: http://code.google.com/p/uby/issues/detail?id=33

--- Judith

On 4 Dez., 16:13, Torsten Zesch <torsten.ze...@gmail.com> wrote:

Torsten Zesch

unread,
Dec 11, 2012, 11:06:17 AM12/11/12
to uby-...@googlegroups.com
Thanks for looking into this.
Is there another way to iterate over all lexical entries?

-Torsten


2012/12/11 Judith Eckle-Kohler <eckle....@googlemail.com>

Judith Eckle-Kohler

unread,
Dec 11, 2012, 11:21:40 AM12/11/12
to UBY Users
I also tried a version without the Iterator, see Issue at Google Code:
http://code.google.com/p/uby/issues/detail?id=33 ,
but it crashes too.

For queries involving all data from large tables such as "all lexical
entries", "all nouns and their semantic labels" I always used direct
SQL queries in the past, because the Hibernate API failed for such
queries.

--- Judith

On 11 Dez., 17:06, Torsten Zesch <torsten.ze...@gmail.com> wrote:
> Thanks for looking into this.
> Is there another way to iterate over all lexical entries?
>
> -Torsten
>
> 2012/12/11 Judith Eckle-Kohler <eckle.koh...@googlemail.com>

Richard Eckart de Castilho

unread,
Dec 11, 2012, 11:31:49 AM12/11/12
to uby-...@googlegroups.com
Hi,

I think the c3p0 pool should actually avoid such situations. You might want to
try configuring it to use a validation query. Wherever the pool is configured
in Uby, try adding these c3p0 properties:

testConnectionOnCheckout=true
testConnectionOnCheckin=true

Cheers,

-- Richard

Torsten Zesch

unread,
Dec 12, 2012, 5:04:39 AM12/12/12
to uby-...@googlegroups.com, richard...@googlemail.com
I tried that, but unfortunately it didn't do the trick. I still get the same exception.

-Torsten

Judith Eckle-Kohler

unread,
Dec 14, 2012, 4:05:56 AM12/14/12
to uby-...@googlegroups.com, richard...@googlemail.com
Hi Torsten,

this is a workaround (which worked for me in a different context):
- use an ordinary SQL query to retrieve all LexicalEntry Ids of the Wiktionary Lexicon you want to query
- then iterate over these LexicalEntry Ids with the (yesterday added) Uby method: getLexicalEntryById(String lexicalEntryId)

The Criteria API currently used in the UBY-API does not work well when retrieving large result sets.

Regards
Judith
Reply all
Reply to author
Forward
0 new messages