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
Closed

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

tacoo opened this issue Jun 15, 2018 · 3 comments · Fixed by #1298
Assignees
Labels
enhancement Improve a feature or add a new feature
Milestone

Comments

@tacoo
Copy link
Contributor

tacoo 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
Copy link
Member

kazuki43zoo 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
Copy link
Contributor Author

tacoo 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
Copy link
Member

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

@kazuki43zoo kazuki43zoo self-assigned this Jun 16, 2018
@kazuki43zoo kazuki43zoo added the enhancement Improve a feature or add a new feature label 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
pulllock pushed a commit to pulllock/mybatis-3 that referenced this issue Oct 19, 2023
pulllock pushed a commit to pulllock/mybatis-3 that referenced this issue Oct 19, 2023
pulllock pushed a commit to pulllock/mybatis-3 that referenced this issue Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve a feature or add a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants