From: George T. <geo...@fr...> - 2005-08-09 20:05:35
Attachments:
err.txt
|
Hello Kal (and Hibernate users) it's me again :-) because the mail breaks the lines and the message is not very easily readable, I am attaching it as plain text also I don't want to bother you, but I don't know what to do here I thing the CLASSPATH and the .jar files are all OK. (the jars are from "tm4j-bin-0.9.8.zip") When I call the following code: Properties props = new Properties (); props.setProperty ("hibernate.dialect","net.sf.hibernate.dialect.MySQLDialect"); props.setProperty ("hibernate.connection.driver_class","com.mysql.jdbc.Driver"); props.setProperty ("hibernate.connection.url","jdbc:mysql://localhost/etm"); props.setProperty ("hibernate.connection.username", "root"); props.setProperty ("hibernate.connection.password", "123"); TopicMapProviderFactory tmpf = new TopicMapProviderFactoryImpl(); TopicMapProvider provider = tmpf.newTopicMapProvider(props); Map mapFeatures = new HashMap (); TMAPITopicMapSystemImpl tmApiSystImpl = new TMAPITopicMapSystemImpl (tmpf.getClass().getName(), props, mapFeatures); Locator loc = provider.getLocatorFactory().createLocator ("URI", tmName); org.tm4j.topicmap.TopicMap tm = provider.getTopicMap (loc); QueryEvaluator qe = QueryEvaluatorFactory.newQueryEvaluator (tm); TologResultsSet rSet = qe.execute ("topic($T)?"); I get from the "qe.execute ("topic($T)?")" the following Exception: 0 [main] ERROR net.sf.hibernate.impl.IteratorImpl - could not get next result java.sql.SQLException: Operation not allowed after ResultSet closed at com.mysql.jdbc.ResultSet.checkClosed(ResultSet.java:3599) at com.mysql.jdbc.ResultSet.next(ResultSet.java:2464) at net.sf.hibernate.impl.IteratorImpl.postNext(IteratorImpl.java:63) at net.sf.hibernate.impl.IteratorImpl.next(IteratorImpl.java:91) at uk.co.jezuk.mango.iterators.TransformingIterator.next(TransformingIterator.j ava:22) at org.tm4j.tologx.predicates.TopicPredicate.matches(TopicPredicate.java:57) at org.tm4j.tologx.predicates.PredicateBase.matches(PredicateBase.java:57) at org.tm4j.tologx.parser.ClauseList.executePredicate(ClauseList.java:124) at org.tm4j.tologx.parser.ClauseList.execute(ClauseList.java:44) at org.tm4j.tologx.parser.TologQuery.execute(TologQuery.java:108) at org.tm4j.tologx.memory.PreparedQueryImpl.execute(PreparedQueryImpl.java:49) at org.tm4j.tologx.memory.QueryEvaluatorImpl.execute(QueryEvaluatorImpl.java:16 7) at etm.Test.main(Test.java:52) net.sf.hibernate.LazyInitializationException: Hibernate lazy instantiation problem at net.sf.hibernate.impl.IteratorImpl.next(IteratorImpl.java:97) at uk.co.jezuk.mango.iterators.TransformingIterator.next(TransformingIterator.j ava:22) at org.tm4j.tologx.predicates.TopicPredicate.matches(TopicPredicate.java:57) at org.tm4j.tologx.predicates.PredicateBase.matches(PredicateBase.java:57) at org.tm4j.tologx.parser.ClauseList.executePredicate(ClauseList.java:124) at org.tm4j.tologx.parser.ClauseList.execute(ClauseList.java:44) at org.tm4j.tologx.parser.TologQuery.execute(TologQuery.java:108) at org.tm4j.tologx.memory.PreparedQueryImpl.execute(PreparedQueryImpl.java:49) at org.tm4j.tologx.memory.QueryEvaluatorImpl.execute(QueryEvaluatorImpl.java:16 7) at etm.Test.main(Test.java:52) Caused by: java.sql.SQLException: Operation not allowed after ResultSet closed at com.mysql.jdbc.ResultSet.checkClosed(ResultSet.java:3599) at com.mysql.jdbc.ResultSet.next(ResultSet.java:2464) at net.sf.hibernate.impl.IteratorImpl.postNext(IteratorImpl.java:63) at net.sf.hibernate.impl.IteratorImpl.next(IteratorImpl.java:91) ... 9 more the "net.sf.hibernate.impl.IteratorImpl.next(IteratorImpl.java:91)" belongs in "hibernate2.jar" the "uk.co.jezuk.mango.iterators.TransformingIterator.next(TransformingIterator. java:22)" belongs in "mango.jar" the "org.tm4j.tologx.predicates.TopicPredicate.matches(TopicPredicate.java:57)" is the: addResultsRow(ret, new Object[] {it.next()}); in the: public VariableSet matches(List params) throws TologProcessingException { VariableSet ret = new VariableSet(); initialiseResultsSet(ret); Object p = params.get(0); if (p instanceof Variable) { Iterator it = getTopicMap().getTopicsIterator(); while (it.hasNext()) { addResultsRow(ret, new Object[] {it.next()}); } } else if (p instanceof Topic) { addResultsRow(ret, new Object[] {p}); } return ret; } inside the TopicPredicate.java I understend that the "it.next()" gets: "java.sql.SQLException: Oeration not allowed after ResultSet closed" I suppose the "getTopicMap().getTopicsIterator()" (in the case of Hibernate) is served by: "org.tm4j.topicmap.hibernate.TopicMapImpl" public Iterator getTopicsIterator() { if (m_provider.isTransactionOpen()) { return getTopicsIterator(m_provider.getOpenTransaction()); } else { ProviderTransaction txn = m_provider.openTransaction(); Iterator ret = getTopicsIterator(txn); txn.rollback(); return ret; } } private Iterator getTopicsIterator(ProviderTransaction txn) { TopicMapDataObject tdo = (TopicMapDataObject) load(txn); Iterator rawIt = iterate(txn, "select topic from topic in class org.tm4j.topicmap.hibernate.TopicDataObject where topic.topicMap = ?", tdo, Hibernate.entity(TopicMapDataObject.class)); return new TransformingIterator(rawIt, getWrapper()); } (The Topic Map works and it is editable, only the Tolog is that is not working) Is it possible that the "Iterator it = getTopicMap().getTopicsIterator();" closes the ResultSet (accidentally) and then return the Iterator? Is anybody uses the combination of Hibernate and Tolog without this problem? Thank you again George Tryfon ____________________________________________________________________ http://www.freemail.gr - δωρεάν υπηρεσία ηλεκτρονικού ταχυδρομείου. http://www.freemail.gr - free email service for the Greek-speaking. |
From: Kal A. <ka...@te...> - 2005-08-10 07:41:46
|
Hi George, I think that it is exactly the problem that you suspect. When the transaction is closed, the results set is also closed. What you will need to do is to wrap your use of the tolog results in its own transaction. So you will need a few extra calls in your sample code: George Tryfon wrote: >Properties props = new Properties (); > >props.setProperty >("hibernate.dialect","net.sf.hibernate.dialect.MySQLDialect"); >props.setProperty >("hibernate.connection.driver_class","com.mysql.jdbc.Driver"); >props.setProperty ("hibernate.connection.url","jdbc:mysql://localhost/etm"); >props.setProperty ("hibernate.connection.username", "root"); >props.setProperty ("hibernate.connection.password", "123"); > >TopicMapProviderFactory tmpf = new TopicMapProviderFactoryImpl(); >TopicMapProvider provider = tmpf.newTopicMapProvider(props); > >Map mapFeatures = new HashMap (); >TMAPITopicMapSystemImpl tmApiSystImpl = new TMAPITopicMapSystemImpl >(tmpf.getClass().getName(), props, mapFeatures); > >Locator loc = provider.getLocatorFactory().createLocator ("URI", tmName); >org.tm4j.topicmap.TopicMap tm = provider.getTopicMap (loc); > >QueryEvaluator qe = QueryEvaluatorFactory.newQueryEvaluator (tm); > > ProviderTransaction txn = provider.openTransaction(); >TologResultsSet rSet = qe.execute ("topic($T)?"); > > > > // Do stuff with rSet txn.abort(); What *should* happen is that the underlying Hibernate topic map provider code should use the transaction you explictly opened for all lookup operations involved in processing the tolog query and it should not try and close the transaction (because it did not open it). I guess this is really a workaround for an underlying problem which is that the Tolog query implementation is not doing the transaction wrapping itself. Although the real issue at the heart of this is that the tolog implementation for Hibernate should be making more use of SQL or Hibernate's query language instead of translating the query into operations against the TM4J API. Neither of those changes are going to happen quickly to the code base (unless someone wants to volunteer!), so in the meantime I recommend that you do this explicit wrapping in your code. In a way it is clearer anyway - even if it does require a bit more typing! Hope this helps**, Kal ** Disclaimer - I haven't actually tried this, but it is my best guess, and its the way that I worked around other issues with iterators returned by the Hibernate implementation. |