Hi,
i just tried the subselect feature. It seems to work fine is some cases, in others not.
Trying to load a "Category" with "parent" (also of type Category) == null produces the following subselect for a set of children entities (of some other type):
select category0_.CATEGORY_ID from CORE_CATEGORY category0_ where category0_.PARENT_ID is null
The statement, of course, works.
But if the Category has a parent, the following subselect is used for subselect fetching:
select category0_.CATEGORY_ID from CORE_CATEGORY category0_ where category0_.PARENT_ID = ?
This does not work. I get the following SQLGrammarException:
Code:
Caused by: org.hibernate.exception.SQLGrammarException: could not load collection by subselect: [de.w3solutions.dms.persistent.core.Category.attributes#<40, 42>]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadCollectionSubselect(Loader.java:1478)
at org.hibernate.loader.collection.SubselectCollectionLoader.initialize(SubselectCollectionLoader.java:55)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:483)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1422)
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:271)
at org.hibernate.engine.PersistenceContext.initializeNonLazyCollections(PersistenceContext.java:796)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:215)
at org.hibernate.loader.Loader.doList(Loader.java:1562)
at org.hibernate.loader.Loader.list(Loader.java:1545)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:840)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at de.w3solutions.dms.database.hibernate.CategoryDAO.loadChildCategories(CategoryDAO.java:63)
... 83 more
Caused by: java.sql.SQLException: Parameter #1 has not been set.
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.prepareSQL(ConnectionJDBC2.java:503)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:666)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:296)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:118)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1239)
at org.hibernate.loader.Loader.doQuery(Loader.java:374)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:210)
at org.hibernate.loader.Loader.loadCollectionSubselect(Loader.java:1473)
... 97 more
I tried to figure out the reasons: The parameter list is, in deed, empty. Somehow the SubselectCollectionLoader gets an empty query parameter list on creation. In the hibernate code (org.hibernate.loader.Loader.doQuery(Loader.java:373)) it seems as if the collection keys are never bound to the prepared statement.
Or am I missing something?
Thx & bye.
Pvblivs
p.s.: my hibernate version is 3.0.3