Mybaits 3.4.1 cursor problem?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Mybaits 3.4.1 cursor problem?

Nie Fei
Hi,

I'm using the latest mybatis 3.4.1. when I use selectCursor("statement"), there is no result returned.

I have tested it with mapper and sqlSession.selectCursor("statement"). Both of them are returned empty result.

I don't know if I used the wrong way?? or there is an issue.

public interface UserDao{
@Select("select NAME, CITY from USER order by ID")
@Results({
@Result(property = "name", column = "T_NAME"),
@Result(property = "city", column = "T_CITY")
})
public Cursor<User> queryAll();
}

I have use a mapper scanner configure way to inject it.

in my test case:

public class TestDao extends BaseContextTest {

@Autowired
private UserDao dao;
@Test
public void testQueryAll(){
for(User usr:dao.queryAll()){
System.out.println(usr.getName);
}
}

there is empty result printed.

But if I change the return type from Cursor to List, it works fine.

public interface UserDao{
@Select("select NAME, CITY from USER order by ID")
@Results({
@Result(property = "name", column = "T_NAME"),
@Result(property = "city", column = "T_CITY")
})
public List<User> queryAll();
}

Also, I used xml configuration way to test. The selectCursor way still failed.

I think this is a BUG? 

Hope you can give me a help.

many thanks.


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Mybaits 3.4.1 cursor problem?

Guy Rouillier-2
I haven't used selectCursor, but I see this statement in the apidocs:
 
"Cursor SQL queries must be ordered (resultOrdered="true") using the id columns of the resultMap."
 
Doesn't appear that you've done this.
 
--
Guy Rouillier
 
 
 
------ Original Message ------
From: "Nie Fei" <[hidden email]>
To: "mybatis-user" <[hidden email]>
Sent: 10/20/2016 4:17:35 AM
Subject: Mybaits 3.4.1 cursor problem?
 
Hi,

I'm using the latest mybatis 3.4.1. when I use selectCursor("statement"), there is no result returned.

I have tested it with mapper and sqlSession.selectCursor("statement"). Both of them are returned empty result.

I don't know if I used the wrong way?? or there is an issue.

public interface UserDao{
@Select("select NAME, CITY from USER order by ID")
@Results({
@Result(property = "name", column = "T_NAME"),
@Result(property = "city", column = "T_CITY")
})
public Cursor<User> queryAll();
}

I have use a mapper scanner configure way to inject it.

in my test case:

public class TestDao extends BaseContextTest {

@Autowired
private UserDao dao;
@Test
public void testQueryAll(){
for(User usr:dao.queryAll()){
System.out.println(usr.getName);
}
}

there is empty result printed.

But if I change the return type from Cursor to List, it works fine.

public interface UserDao{
@Select("select NAME, CITY from USER order by ID")
@Results({
@Result(property = "name", column = "T_NAME"),
@Result(property = "city", column = "T_CITY")
})
public List<User> queryAll();
}

Also, I used xml configuration way to test. The selectCursor way still failed.

I think this is a BUG? 

Hope you can give me a help.

many thanks.


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

Virus-free. www.avast.com

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Mybaits 3.4.1 cursor problem?

Kazuki Shimizu
In reply to this post by Nie Fei
Hi Nie Fei ,

If possible, please provide a repro project via GitHub repository.
Thanks.

On Friday, October 21, 2016 at 11:19:00 AM UTC+9, Nie Fei wrote:
Hi,

I'm using the latest mybatis 3.4.1. when I use selectCursor("statement"), there is no result returned.

I have tested it with mapper and sqlSession.selectCursor("statement"). Both of them are returned empty result.

I don't know if I used the wrong way?? or there is an issue.

public interface UserDao{
@Select("select NAME, CITY from USER order by ID")
@Results({
@Result(property = "name", column = "T_NAME"),
@Result(property = "city", column = "T_CITY")
})
public Cursor<User> queryAll();
}

I have use a mapper scanner configure way to inject it.

in my test case:

public class TestDao extends BaseContextTest {

@Autowired
private UserDao dao;
@Test
public void testQueryAll(){
for(User usr:dao.queryAll()){
System.out.println(usr.getName);
}
}

there is empty result printed.

But if I change the return type from Cursor to List, it works fine.

public interface UserDao{
@Select("select NAME, CITY from USER order by ID")
@Results({
@Result(property = "name", column = "T_NAME"),
@Result(property = "city", column = "T_CITY")
})
public List<User> queryAll();
}

Also, I used xml configuration way to test. The selectCursor way still failed.

I think this is a BUG? 

Hope you can give me a help.

many thanks.


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Mybaits 3.4.1 cursor problem?

Nie Fei
Hi,

Today, I found the reason finally.

When I create the repro project, I found it works fine without spring framework. But my spring3 + mybatis project still has the empty issue.

Further, I debugged the codes, found the cursor only works when it's called in transaction. If not, the sqlSessionTemplate will close the session and cursor, when the selectCursor returned back, then I saw the empty issue.

Thanks,
BR,
/niefei 


在 2016年10月22日星期六 UTC+8上午12:51:00,Kazuki Shimizu写道:
Hi Nie Fei ,

If possible, please provide a repro project via GitHub repository.
Thanks.

On Friday, October 21, 2016 at 11:19:00 AM UTC+9, Nie Fei wrote:
Hi,

I'm using the latest mybatis 3.4.1. when I use selectCursor("statement"), there is no result returned.

I have tested it with mapper and sqlSession.selectCursor("statement"). Both of them are returned empty result.

I don't know if I used the wrong way?? or there is an issue.

public interface UserDao{
@Select("select NAME, CITY from USER order by ID")
@Results({
@Result(property = "name", column = "T_NAME"),
@Result(property = "city", column = "T_CITY")
})
public Cursor<User> queryAll();
}

I have use a mapper scanner configure way to inject it.

in my test case:

public class TestDao extends BaseContextTest {

@Autowired
private UserDao dao;
@Test
public void testQueryAll(){
for(User usr:dao.queryAll()){
System.out.println(usr.getName);
}
}

there is empty result printed.

But if I change the return type from Cursor to List, it works fine.

public interface UserDao{
@Select("select NAME, CITY from USER order by ID")
@Results({
@Result(property = "name", column = "T_NAME"),
@Result(property = "city", column = "T_CITY")
})
public List<User> queryAll();
}

Also, I used xml configuration way to test. The selectCursor way still failed.

I think this is a BUG? 

Hope you can give me a help.

many thanks.


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Mybaits 3.4.1 cursor problem?

Nie Fei
In reply to this post by Guy Rouillier-2
Hi,

It looks like the selectCursor must be called in transaction. Otherwise, the cursor will be closed before selectCursor returned back.

thank you.

BR,
/niefei

在 2016年10月21日星期五 UTC+8下午2:11:15,Guy Rouillier写道:
I haven't used selectCursor, but I see this statement in the apidocs:
 
"Cursor SQL queries must be ordered (resultOrdered="true") using the id columns of the resultMap."
 
Doesn't appear that you've done this.
 
--
Guy Rouillier
 
 
 
------ Original Message ------
From: "Nie Fei" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="CRi_gzjSAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">tecl...@...>
To: "mybatis-user" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="CRi_gzjSAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybati...@...>
Sent: 10/20/2016 4:17:35 AM
Subject: Mybaits 3.4.1 cursor problem?
 
Hi,

I'm using the latest mybatis 3.4.1. when I use selectCursor("statement"), there is no result returned.

I have tested it with mapper and sqlSession.selectCursor("statement"). Both of them are returned empty result.

I don't know if I used the wrong way?? or there is an issue.

public interface UserDao{
@Select("select NAME, CITY from USER order by ID")
@Results({
@Result(property = "name", column = "T_NAME"),
@Result(property = "city", column = "T_CITY")
})
public Cursor<User> queryAll();
}

I have use a mapper scanner configure way to inject it.

in my test case:

public class TestDao extends BaseContextTest {

@Autowired
private UserDao dao;
@Test
public void testQueryAll(){
for(User usr:dao.queryAll()){
System.out.println(usr.getName);
}
}

there is empty result printed.

But if I change the return type from Cursor to List, it works fine.

public interface UserDao{
@Select("select NAME, CITY from USER order by ID")
@Results({
@Result(property = "name", column = "T_NAME"),
@Result(property = "city", column = "T_CITY")
})
public List<User> queryAll();
}

Also, I used xml configuration way to test. The selectCursor way still failed.

I think this is a BUG? 

Hope you can give me a help.

many thanks.


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="CRi_gzjSAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybatis-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

<a href="https://www.avast.com/sig-email?utm_medium=email&amp;utm_source=link&amp;utm_campaign=sig-email&amp;utm_content=emailclient&amp;utm_term=icon" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.avast.com%2Fsig-email%3Futm_medium%3Demail%26utm_source%3Dlink%26utm_campaign%3Dsig-email%26utm_content%3Demailclient%26utm_term%3Dicon\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGdgn6XHtGdGX0_ztl7zsznn9rycA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.avast.com%2Fsig-email%3Futm_medium%3Demail%26utm_source%3Dlink%26utm_campaign%3Dsig-email%26utm_content%3Demailclient%26utm_term%3Dicon\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGdgn6XHtGdGX0_ztl7zsznn9rycA&#39;;return true;"> Virus-free. <a href="https://www.avast.com/sig-email?utm_medium=email&amp;utm_source=link&amp;utm_campaign=sig-email&amp;utm_content=emailclient&amp;utm_term=link" style="color:#4453ea" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.avast.com%2Fsig-email%3Futm_medium%3Demail%26utm_source%3Dlink%26utm_campaign%3Dsig-email%26utm_content%3Demailclient%26utm_term%3Dlink\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEBTW1oVO7X9WxlATGseHnM8Gn-HQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.avast.com%2Fsig-email%3Futm_medium%3Demail%26utm_source%3Dlink%26utm_campaign%3Dsig-email%26utm_content%3Demailclient%26utm_term%3Dlink\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEBTW1oVO7X9WxlATGseHnM8Gn-HQ&#39;;return true;">www.avast.com

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.