Ibatis自我关联的立即加载

一个Chapter表自我一对多关联。对象属性如下:[code="java"]
private int cid;
private Chapter parent;
private List children;
[/code]
现在需要到数据库查询一个Root对象和对应的子Chapter以及子Chapter的子Chapter。。。
也就是得到一个树形结构的对象,现在使用延迟加载没有问题,SQL代码如下:
[code="java"]










SELECT

FROM

WHERE cid =1



SELECT

FROM

WHERE cid =#cid#




SELECT

FROM

WHERE pid =#cid#

[/code]
现在我想实现立即加载有什么办法呢,我试过lazyLoadingEnabled="false" enhancementEnabled="false",但是还是不行。

[b]问题补充:[/b]
谢谢一楼的回复,我在Setting里面设置的,当设计为False时掏出一下异常:
org.springframework.dao.DataAccessResourceFailureException: SqlMapClient operation; SQL [];

--- The error occurred in com/sixclk/clickmath/dao/Chapter-Pgsql.xml.

--- The error occurred while applying a result map.

--- Check the Chapter.Result.

--- Check the result mapping for the 'children' property.

--- Cause: com.ibatis.common.jdbc.exception.NestedSQLException:

--- The error occurred in com/sixclk/clickmath/dao/Chapter-Pgsql.xml.

--- The error occurred while applying a result map.

--- Check the Chapter.Result.

--- Check the result mapping for the 'parent' property.

--- Cause: com.ibatis.common.jdbc.exception.NestedSQLException:

--- The error occurred in com/sixclk/clickmath/dao/Chapter-Pgsql.xml.

--- The error occurred while applying a result map.

--- Check the Chapter.Result.

--- Check the result mapping for the 'children' property.

--- Cause: org.postgresql.util.PSQLException: 这个 ResultSet 已经被关闭。; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:

--- The error occurred in com/sixclk/clickmath/dao/Chapter-Pgsql.xml.

--- The error occurred while applying a result map.

--- Check the Chapter.Result.

--- Check the result mapping for the 'children' property.

--- Cause: com.ibatis.common.jdbc.exception.NestedSQLException:

--- The error occurred in com/sixclk/clickmath/dao/Chapter-Pgsql.xml.

--- The error occurred while applying a result map.

--- Check the Chapter.Result.

--- Check the result mapping for the 'parent' property.

--- Cause: com.ibatis.common.jdbc.exception.NestedSQLException:

--- The error occurred in com/sixclk/clickmath/dao/Chapter-Pgsql.xml.

--- The error occurred while applying a result map.

--- Check the Chapter.Result.

--- Check the result mapping for the 'children' property.

--- Cause: org.postgresql.util.PSQLException: 这个 ResultSet 已经被关闭。
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:103)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:212)
at org.springframework.orm.ibatis.SqlMapClientTemplate.executeWithListResult(SqlMapClientTemplate.java:249)
at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:296)
at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:290)
at com.sixclk.clickmath.dao.ChapterDAOImpl.getAllChapter(ChapterDAOImpl.java:14)
at sixclk.clickmath.persistance.ChapterDAOTest.testGetAllChapter(ChapterDAOTest.java:12)
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:597)
at org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestMethod.java:163)
at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:233)
at org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:333)
at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)
at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)
at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:142)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
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: com.ibatis.common.jdbc.exception.NestedSQLException:

--- The error occurred in com/sixclk/clickmath/dao/Chapter-Pgsql.xml.

--- The error occurred while applying a result map.

--- Check the Chapter.Result.

--- Check the result mapping for the 'children' property.

--- Cause: com.ibatis.common.jdbc.exception.NestedSQLException:

--- The error occurred in com/sixclk/clickmath/dao/Chapter-Pgsql.xml.

--- The error occurred while applying a result map.

--- Check the Chapter.Result.

--- Check the result mapping for the 'parent' property.

--- Cause: com.ibatis.common.jdbc.exception.NestedSQLException:

--- The error occurred in com/sixclk/clickmath/dao/Chapter-Pgsql.xml.

--- The error occurred while applying a result map.

--- Check the Chapter.Result.

--- Check the result mapping for the 'children' property.

--- Cause: org.postgresql.util.PSQLException: 这个 ResultSet 已经被关闭。
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:201)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForList(MappedStatement.java:139)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:567)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:541)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:118)
at org.springframework.orm.ibatis.SqlMapClientTemplate$3.doInSqlMapClient(SqlMapClientTemplate.java:298)
at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:209)
... 27 more
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:

--- The error occurred in com/sixclk/clickmath/dao/Chapter-Pgsql.xml.

--- The error occurred while applying a result map.

--- Check the Chapter.Result.

--- Check the result mapping for the 'parent' property.

--- Cause: com.ibatis.common.jdbc.exception.NestedSQLException:

--- The error occurred in com/sixclk/clickmath/dao/Chapter-Pgsql.xml.

--- The error occurred while applying a result map.

--- Check the Chapter.Result.

--- Check the result mapping for the 'children' property.

--- Cause: org.postgresql.util.PSQLException: 这个 ResultSet 已经被关闭。
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:201)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForList(MappedStatement.java:139)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:567)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:541)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:118)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:94)
at com.ibatis.sqlmap.engine.mapping.result.loader.ResultLoader.getResult(ResultLoader.java:70)
at com.ibatis.sqlmap.engine.mapping.result.loader.ResultLoader.loadResult(ResultLoader.java:57)
at com.ibatis.sqlmap.engine.mapping.result.ResultMap.getNestedSelectMappingValue(ResultMap.java:510)
at com.ibatis.sqlmap.engine.mapping.result.ResultMap.getResults(ResultMap.java:341)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:384)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:300)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:189)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteQuery(MappedStatement.java:221)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189)
... 33 more
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:

--- The error occurred in com/sixclk/clickmath/dao/Chapter-Pgsql.xml.

--- The error occurred while applying a result map.

--- Check the Chapter.Result.

--- Check the result mapping for the 'children' property.

--- Cause: org.postgresql.util.PSQLException: 这个 ResultSet 已经被关闭。
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:201)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForObject(MappedStatement.java:120)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:518)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:493)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(SqlMapClientImpl.java:82)
at com.ibatis.sqlmap.engine.mapping.result.loader.ResultLoader.getResult(ResultLoader.java:75)
at com.ibatis.sqlmap.engine.mapping.result.loader.ResultLoader.loadResult(ResultLoader.java:57)
at com.ibatis.sqlmap.engine.mapping.result.ResultMap.getNestedSelectMappingValue(ResultMap.java:510)
at com.ibatis.sqlmap.engine.mapping.result.ResultMap.getResults(ResultMap.java:341)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:384)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:300)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:189)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteQuery(MappedStatement.java:221)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189)
... 47 more
Caused by: org.postgresql.util.PSQLException: 这个 ResultSet 已经被关闭。
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.checkClosed(AbstractJdbc2ResultSet.java:2674)
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.findColumn(AbstractJdbc2ResultSet.java:2558)
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getInt(AbstractJdbc2ResultSet.java:2426)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.getInt(NewProxyResultSet.java:2573)
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:597)
at com.ibatis.common.jdbc.logging.ResultSetLogProxy.invoke(ResultSetLogProxy.java:47)
at $Proxy14.getInt(Unknown Source)
at com.ibatis.sqlmap.engine.type.IntegerTypeHandler.getResult(IntegerTypeHandler.java:35)
at com.ibatis.sqlmap.engine.mapping.result.ResultMap.preparePrimitiveParameterObject(ResultMap.java:533)
at com.ibatis.sqlmap.engine.mapping.result.ResultMap.getNestedSelectMappingValue(ResultMap.java:487)
at com.ibatis.sqlmap.engine.mapping.result.ResultMap.getResults(ResultMap.java:341)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:384)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:300)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:189)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteQuery(MappedStatement.java:221)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189)
... 61 more

1个回答

你是在元素中设置这两个属性的吗,如果是,那应该就能出来效果的

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问