Skip to content

Commit 5c239b5

Browse files
committed
Fixes #167. @one is broken in 3.2.6
1 parent d39481b commit 5c239b5

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationBuilder.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,13 +517,10 @@ private boolean isLazy(Result result) {
517517
}
518518

519519
private boolean hasNestedSelect(Result result) {
520-
boolean hasNestedSelect = result.one().select().length() > 0;
521-
if (hasNestedSelect) {
520+
if (result.one().select().length() > 0 && result.many().select().length() > 0) {
522521
throw new BuilderException("Cannot use both @One and @Many annotations in the same @Result");
523-
} else {
524-
hasNestedSelect = result.many().select().length() > 0;
525522
}
526-
return hasNestedSelect;
523+
return result.one().select().length() > 0 || result.many().select().length() > 0;
527524
}
528525

529526
private void applyConstructorArgs(Arg[] args, Class<?> resultType, List<ResultMapping> resultMappings) {

src/test/java/org/apache/ibatis/binding/BindingTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,20 @@ public void shouldExecuteBoundSelectListOfBlogsStatement() {
190190
}
191191
}
192192

193+
@Test
194+
public void shouldGetBlogsWithAuthors() {
195+
SqlSession session = sqlSessionFactory.openSession();
196+
try {
197+
BoundBlogMapper mapper = session.getMapper(BoundBlogMapper.class);
198+
List<Blog> blogs = mapper.selectBlogsWithAutors();
199+
assertEquals(2, blogs.size());
200+
assertEquals(101, blogs.get(0).getAuthor().getId());
201+
assertEquals(102, blogs.get(1).getAuthor().getId());
202+
} finally {
203+
session.close();
204+
}
205+
}
206+
193207
@Test
194208
public void shouldExecuteBoundSelectMapOfBlogsById() {
195209
SqlSession session = sqlSessionFactory.openSession();

src/test/java/org/apache/ibatis/binding/BoundBlogMapper.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,12 @@ List<Post> selectPostsLikeSubjectAndBody(RowBounds bounds,
166166
"WHERE ${column} = #{id} AND title = #{value}")
167167
Blog selectBlogWithAParamNamedValue(@Param("column") String column, @Param("id") int id, @Param("value") String title);
168168

169+
@Select({
170+
"SELECT *",
171+
"FROM blog"
172+
})
173+
@Results({ @Result(property = "author", column = "author_id", one = @One(select = "org.apache.ibatis.binding.BoundAuthorMapper.selectAuthor")) })
174+
List<Blog> selectBlogsWithAutors();
175+
169176

170177
}

0 commit comments

Comments
 (0)