为什么我的 Cursor 是空的?
Why my Cursor is empty?
我正在尝试使用 MyBatis 的 Cursor。
映射器XML
<select id="selectCursor51" resultMap="someResultMap" resultOrdered="true">
SELECT
...
FROM
...
<where>
...
</where>
ORDER BY
..., <!-- is this part can be wrong? -->
some_id ASC
</select>
映射器接口,
@Mapper
public interface SomeMapper {
List<Some> selectCursor51(...);
}
Spring服务,
@Service
public class SomeService {
@Transactional
public <R> R some(..., final Function<Cursor<Some>, R> function) {
...
final Cursor<Some> cursor = someMapper.selectCursor51(...);
return function.apply(cursor);
}
@Autowired
private SomeMapper someMapper;
}
实际查询产生非空结果。
但是光标是空的。
我做错了什么?
我正在用更新回答我自己的问题。
这个方法确实有效。
问题是直接或间接调用方法较多
@Transactional
public <R> R some(..., final Function<Cursor<Some>, R> function) {
return function.apply(someMapper.selectCursor51(...));
}
// not annotated with @Transactional
public void some(..., final Consumer<Some> consumer) {
some(
...,
cursor -> {
for(Some some: cursor) {
consumer.accept(some);
}
}
);
}
当,比如说一个控制器,用一个用 @Transactional
注释的函数调用 some 时,它就起作用了。
当它调用消费者的 some 方法时,它不会。
我找到 @Transactional method calling another method without @Transactional anotation? 并解决了我的问题。
我正在尝试使用 MyBatis 的 Cursor。
映射器XML
<select id="selectCursor51" resultMap="someResultMap" resultOrdered="true">
SELECT
...
FROM
...
<where>
...
</where>
ORDER BY
..., <!-- is this part can be wrong? -->
some_id ASC
</select>
映射器接口,
@Mapper
public interface SomeMapper {
List<Some> selectCursor51(...);
}
Spring服务,
@Service
public class SomeService {
@Transactional
public <R> R some(..., final Function<Cursor<Some>, R> function) {
...
final Cursor<Some> cursor = someMapper.selectCursor51(...);
return function.apply(cursor);
}
@Autowired
private SomeMapper someMapper;
}
实际查询产生非空结果。 但是光标是空的。
我做错了什么?
我正在用更新回答我自己的问题。
这个方法确实有效。
问题是直接或间接调用方法较多
@Transactional
public <R> R some(..., final Function<Cursor<Some>, R> function) {
return function.apply(someMapper.selectCursor51(...));
}
// not annotated with @Transactional
public void some(..., final Consumer<Some> consumer) {
some(
...,
cursor -> {
for(Some some: cursor) {
consumer.accept(some);
}
}
);
}
当,比如说一个控制器,用一个用 @Transactional
注释的函数调用 some 时,它就起作用了。
当它调用消费者的 some 方法时,它不会。
我找到 @Transactional method calling another method without @Transactional anotation? 并解决了我的问题。