Skip to content

Commit f8ddba3

Browse files
committed
Lazy loading defaults to false. Fix for http://code.google.com/p/mybatis/issues/detail?id=144 .
1 parent df0f135 commit f8ddba3

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/main/java/org/apache/ibatis/builder/xml/XMLConfigBuilder.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private void settingsElement(XNode context) throws Exception {
153153
}
154154
configuration.setAutoMappingBehavior(AutoMappingBehavior.valueOf(stringValueOf(props.getProperty("autoMappingBehavior"), "PARTIAL")));
155155
configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"), true));
156-
configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), safeCglibCheck()));
156+
configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), false));
157157
configuration.setAggressiveLazyLoading(booleanValueOf(props.getProperty("aggressiveLazyLoading"), true));
158158
configuration.setMultipleResultSetsEnabled(booleanValueOf(props.getProperty("multipleResultSetsEnabled"), true));
159159
configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"), true));
@@ -163,14 +163,6 @@ private void settingsElement(XNode context) throws Exception {
163163
}
164164
}
165165

166-
private boolean safeCglibCheck() {
167-
try {
168-
return Resources.classForName("net.sf.cglib.proxy.Enhancer") != null;
169-
} catch (Exception e) {
170-
return false;
171-
}
172-
}
173-
174166
private void environmentsElement(XNode context) throws Exception {
175167
if (context != null) {
176168
if (environment == null) {

src/main/java/org/apache/ibatis/session/Configuration.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.ibatis.executor.statement.RoutingStatementHandler;
2323
import org.apache.ibatis.executor.statement.StatementHandler;
2424
import org.apache.ibatis.io.ResolverUtil;
25+
import org.apache.ibatis.io.Resources;
2526
import org.apache.ibatis.mapping.*;
2627
import org.apache.ibatis.parsing.XNode;
2728
import org.apache.ibatis.plugin.Interceptor;
@@ -131,6 +132,13 @@ public boolean isLazyLoadingEnabled() {
131132
}
132133

133134
public void setLazyLoadingEnabled(boolean lazyLoadingEnabled) {
135+
if (lazyLoadingEnabled) {
136+
try {
137+
Resources.classForName("net.sf.cglib.proxy.Enhancer");
138+
} catch (Throwable e) {
139+
throw new IllegalArgumentException("Cannot enable lazy loading because CGLIB is not available. Add CGLIB to your classpath.", e);
140+
}
141+
}
134142
this.lazyLoadingEnabled = lazyLoadingEnabled;
135143
}
136144

@@ -525,7 +533,7 @@ protected void checkLocallyForDiscriminatedNestedResultMaps(ResultMap rm) {
525533
}
526534
}
527535
}
528-
536+
529537
protected static class StrictMap<J extends String, K extends Object> extends HashMap<J, K> {
530538

531539
private String name;

0 commit comments

Comments
 (0)