Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty Iterator returned on Cursor when it is already closed #1297

Closed
tacoo opened this issue Jun 15, 2018 · 3 comments · Fixed by #1298

Comments

@tacoo
Copy link

commented Jun 15, 2018

MyBatis version

mybatis-spring-boot-starter: 1.3.2
mybatis: 3.4.6

Database vendor and version

PostgreSQL: 9.6

Test case or example project

https://github.com/tacoo/mybatis-cursor

Steps to reproduce

Define a mapper method with return type org.apache.ibatis.cursor.Cursor
https://github.com/tacoo/mybatis-cursor/blob/master/src/main/java/example/AMapper.java#L14

Also I tested a method with return type org.apache.ibatis.session.ResultHandler. It works as expected.

Expected result

Return a cursor that has 1 record.

Actual result

Returned an empty cursor.

@kazuki43zoo

This comment has been minimized.

Copy link
Member

commented Jun 15, 2018

@tacoo Thanks for your reporting.

You should be operated a Cursor with session is opened. In your application(= using mapper in spring application), you should be operated a Cursor at transactional method as follow:

@Repository
public class ARepository {

	private final AMapper aMapper;

+	@Transactional(readOnly = true)
	public void whyCursorWhy() {
		cursor();
		resultHandler();
	}

	// ...

}
@tacoo

This comment has been minimized.

Copy link
Author

commented Jun 16, 2018

@kazuki43zoo

Thank you for your prompt reply.

It worked after adding Transactional annotation on the repository method. I understood that it requires to open a session before use a Cursor.

I think it would be great if mybatis throws an error when return type Cursor method called without opened session.

Thank you

kazuki43zoo added a commit to kazuki43zoo/mybatis-3 that referenced this issue Jun 16, 2018
kazuki43zoo added a commit to kazuki43zoo/mybatis-3 that referenced this issue Jun 16, 2018

@kazuki43zoo kazuki43zoo changed the title Empty cursor returned Empty Iterator returned on Cursor when it is already closed Jun 16, 2018

@kazuki43zoo

This comment has been minimized.

Copy link
Member

commented Jun 16, 2018

@tacoo Thanks for your feedback.
I've submitted a PR for this.

@kazuki43zoo kazuki43zoo self-assigned this Jun 16, 2018

kazuki43zoo added a commit to kazuki43zoo/mybatis-3 that referenced this issue Jul 23, 2018

@kazuki43zoo kazuki43zoo added this to the 3.5.0 milestone Sep 1, 2018

h3adache pushed a commit to h3adache/mybatis-3 that referenced this issue Sep 14, 2018
Merge pull request mybatis#1298 from kazuki43zoo/mybatisgh-1297
Add closed check at Cursor.iterator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.