Upgrade from Mybatis 3.4.1 to 3.4.2 breaks code that uses #{0}

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

Upgrade from Mybatis 3.4.1 to 3.4.2 breaks code that uses #{0}

k mac
Hello,

Yesterday, we upgraded from MyBatis 3.4.1 to 3.4.2. As a result, our Java code such as the following no longer works:

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{0} and client_app = #{1, typeHandler=com.loxcel.db.table.ClientAppTypeHandler} and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")

In order to comply with the changes made to 3.4.2, #{0} and #{1} from the code above must be replaced with #{arg0} and #{arg1}

Thus, in order for us to upgrade to 3.4.2 from 3.4.1 we will need to change a significant amount of code.

I doubt we're the only ones using MyBatis this way, so am I missing something or does 3.4.2 intentionally break a lot of existing code?


--
Thank you


Kevin Macdonald
Partner | Loxcel Geomatics

--
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: Upgrade from Mybatis 3.4.1 to 3.4.2 breaks code that uses #{0}

Kazuki Shimizu
Probably, it relates with https://github.com/mybatis/mybatis-3/issues/549.

Let's try adding following setting in your application.

<settings>
  <setting name="useActualParamName" value="false" />
</settings>

However,  I don't know a reason that working on MyBatis 3.4.1 because this feature support at MyBatis 3.4.1.

Thanks.


On Thursday, January 12, 2017 at 9:37:06 AM UTC+9, k mac wrote:
Hello,

Yesterday, we upgraded from MyBatis 3.4.1 to 3.4.2. As a result, our Java code such as the following no longer works:

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{0} and client_app = #{1, typeHandler=com.loxcel.db.table.ClientAppTypeHandler} and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")

In order to comply with the changes made to 3.4.2, #{0} and #{1} from the code above must be replaced with #{arg0} and #{arg1}

Thus, in order for us to upgrade to 3.4.2 from 3.4.1 we will need to change a significant amount of code.

I doubt we're the only ones using MyBatis this way, so am I missing something or does 3.4.2 intentionally break a lot of existing code?


--
Thank you


Kevin Macdonald
Partner | Loxcel Geomatics
<a href="http://www.loxcel.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.loxcel.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFdch23wHqWmFtlZLjzt6Ckc6m6wg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.loxcel.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFdch23wHqWmFtlZLjzt6Ckc6m6wg&#39;;return true;">www.loxcel.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: Upgrade from Mybatis 3.4.1 to 3.4.2 breaks code that uses #{0}

Iwao AVE!
In reply to this post by k mac
Hi Kevin,

It was supposed to break in 3.4.1 by the enhancement #549 .
In 3.4.1, the default value of 'useActualParameterName' was set to 'false' by my mistake and was corrected in 3.4.2.


> If a project uses legacy style parameter references with index numbers (i.e. #{0}, #{1}, ...) and is compiled with '-parameters' option, you may have to set useActualParameterName to false in the config.

So, if you are not going to use this feature, setting 'useActualParameterName' to false should fix the problem (or disable '-parameters' compiler option).

FYI, this legacy style parameter reference (i.e. #{0}, #{1}) had some incompatibility with OGNL and the new style (i.e. #{param1}, #{param2}) is recommended.

Regards,
Iwao


2017-01-12 1:11 GMT+09:00 k mac <[hidden email]>:
Hello,

Yesterday, we upgraded from MyBatis 3.4.1 to 3.4.2. As a result, our Java code such as the following no longer works:

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{0} and client_app = #{1, typeHandler=com.loxcel.db.table.ClientAppTypeHandler} and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")

In order to comply with the changes made to 3.4.2, #{0} and #{1} from the code above must be replaced with #{arg0} and #{arg1}

Thus, in order for us to upgrade to 3.4.2 from 3.4.1 we will need to change a significant amount of code.

I doubt we're the only ones using MyBatis this way, so am I missing something or does 3.4.2 intentionally break a lot of existing code?


--
Thank you


Kevin Macdonald
Partner | Loxcel Geomatics

--
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.

--
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: Upgrade from Mybatis 3.4.1 to 3.4.2 breaks code that uses #{0}

Iwao AVE!
Correction.

 (or disable '-parameters' compiler option)

Sorry, this may not work.

2017-01-12 10:26 GMT+09:00 Iwao AVE! <[hidden email]>:
Hi Kevin,

It was supposed to break in 3.4.1 by the enhancement #549 .
In 3.4.1, the default value of 'useActualParameterName' was set to 'false' by my mistake and was corrected in 3.4.2.


> If a project uses legacy style parameter references with index numbers (i.e. #{0}, #{1}, ...) and is compiled with '-parameters' option, you may have to set useActualParameterName to false in the config.

So, if you are not going to use this feature, setting 'useActualParameterName' to false should fix the problem (or disable '-parameters' compiler option).

FYI, this legacy style parameter reference (i.e. #{0}, #{1}) had some incompatibility with OGNL and the new style (i.e. #{param1}, #{param2}) is recommended.

Regards,
Iwao


2017-01-12 1:11 GMT+09:00 k mac <[hidden email]>:
Hello,

Yesterday, we upgraded from MyBatis 3.4.1 to 3.4.2. As a result, our Java code such as the following no longer works:

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{0} and client_app = #{1, typeHandler=com.loxcel.db.table.ClientAppTypeHandler} and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")

In order to comply with the changes made to 3.4.2, #{0} and #{1} from the code above must be replaced with #{arg0} and #{arg1}

Thus, in order for us to upgrade to 3.4.2 from 3.4.1 we will need to change a significant amount of code.

I doubt we're the only ones using MyBatis this way, so am I missing something or does 3.4.2 intentionally break a lot of existing code?


--
Thank you


Kevin Macdonald
Partner | Loxcel Geomatics

--
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.


--
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: Upgrade from Mybatis 3.4.1 to 3.4.2 breaks code that uses #{0}

k mac
In reply to this post by k mac
Iwao,

Issue #549 sounds like a sensible change. So, I modified my code as follows

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{account} and client_app = #{clientApp,typeHandler=com.loxcel.db.table.ClientAppTypeHandler} and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")
@Results( {
@Result(property="clientApp", column="client_app", typeHandler=ClientAppTypeHandler.class)
})
public Subscription selectCurrent (int account, ClientApp clientApp);


but I now get this exception:

### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'account' not found. Available parameters are [arg1, arg0, param1, param2]
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'account' not found. Available parameters are [arg1, arg0, param1, param2]"
2017-01-18 11:23:28.392,SEVERE,com.loxcel.util.net.webservice.IWebService,service,
org.apache.ibatis.exceptions.PersistenceException (
### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'account' not found. Available parameters are [arg1, arg0, param1, param2]
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'account' not found. Available parameters are [arg1, arg0, param1, param2]) was thrown from
          org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77)
          org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
          org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
          com.sun.proxy.$Proxy18.selectCurrent(Unknown Source)
          com.loxcel.backoffice.SubscriptionTxn.selectCurrent(SubscriptionTxn.java:84)


Now, if I change this one line

+ " WHERE account = #{account} and client_app = #{clientApp,typeHandler=com.loxcel.db.table.ClientAppTypeHandler} and now () between begin and expire"

to

+ " WHERE account = #{arg0} and client_app = #{arg1,typeHandler=com.loxcel.db.table.ClientAppTypeHandler} and now () between begin and expire"


all is ok and the program runs correctly.


However, I don't understand how the requirement to use #{arg0} is any better than #{0} ??


Thanks

Kevin


On Wednesday, January 11, 2017 at 7:37:06 PM UTC-5, k mac wrote:
Hello,

Yesterday, we upgraded from MyBatis 3.4.1 to 3.4.2. As a result, our Java code such as the following no longer works:

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{0} and client_app = #{1, typeHandler=com.loxcel.db.table.ClientAppTypeHandler} and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")

In order to comply with the changes made to 3.4.2, #{0} and #{1} from the code above must be replaced with #{arg0} and #{arg1}

Thus, in order for us to upgrade to 3.4.2 from 3.4.1 we will need to change a significant amount of code.

I doubt we're the only ones using MyBatis this way, so am I missing something or does 3.4.2 intentionally break a lot of existing code?

--
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: Upgrade from Mybatis 3.4.1 to 3.4.2 breaks code that uses #{0}

Kazuki Shimizu
Hi Kevin,

If you want to use actual parameter variable name, you should be specified -parameters compile option provided by JDK 8 on compile time.

Do you understand?


On Thursday, January 19, 2017 at 1:34:30 AM UTC+9, [hidden email] wrote:
Iwao,

Issue #549 sounds like a sensible change. So, I modified my code as follows

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{account} and client_app = #{clientApp,typeHandler=com.loxcel.db.table.ClientAppTypeHandler} and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")
@Results( {
@Result(property="clientApp", column="client_app", typeHandler=ClientAppTypeHandler.class)
})
public Subscription selectCurrent (int account, ClientApp clientApp);


but I now get this exception:

### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'account' not found. Available parameters are [arg1, arg0, param1, param2]
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'account' not found. Available parameters are [arg1, arg0, param1, param2]"
2017-01-18 11:23:28.392,SEVERE,com.loxcel.util.net.webservice.IWebService,service,
org.apache.ibatis.exceptions.PersistenceException (
### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'account' not found. Available parameters are [arg1, arg0, param1, param2]
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'account' not found. Available parameters are [arg1, arg0, param1, param2]) was thrown from
          org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77)
          org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
          org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
          com.sun.proxy.$Proxy18.selectCurrent(Unknown Source)
          com.loxcel.backoffice.SubscriptionTxn.selectCurrent(SubscriptionTxn.java:84)


Now, if I change this one line

+ " WHERE account = #{account} and client_app = #{clientApp,typeHandler=com.loxcel.db.table.ClientAppTypeHandler} and now () between begin and expire"

to

+ " WHERE account = #{arg0} and client_app = #{arg1,typeHandler=com.loxcel.db.table.ClientAppTypeHandler} and now () between begin and expire"


all is ok and the program runs correctly.


However, I don't understand how the requirement to use #{arg0} is any better than #{0} ??


Thanks

Kevin


On Wednesday, January 11, 2017 at 7:37:06 PM UTC-5, k mac wrote:
Hello,

Yesterday, we upgraded from MyBatis 3.4.1 to 3.4.2. As a result, our Java code such as the following no longer works:

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{0} and client_app = #{1, typeHandler=com.loxcel.db.table.ClientAppTypeHandler} and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")

In order to comply with the changes made to 3.4.2, #{0} and #{1} from the code above must be replaced with #{arg0} and #{arg1}

Thus, in order for us to upgrade to 3.4.2 from 3.4.1 we will need to change a significant amount of code.

I doubt we're the only ones using MyBatis this way, so am I missing something or does 3.4.2 intentionally break a lot of existing code?

--
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: Upgrade from Mybatis 3.4.1 to 3.4.2 breaks code that uses #{0}

Iwao AVE!
Kazuki is right.
Without the '-parameters' option, the compiler uses these default names (arg0, arg1, ...).

If you are using Eclipse, you may need to enable 'Store information about method parameters' option in the Java Compiler setting.

Regards,
Iwao


2017-01-19 1:47 GMT+09:00 Kazuki Shimizu <[hidden email]>:
Hi Kevin,

If you want to use actual parameter variable name, you should be specified -parameters compile option provided by JDK 8 on compile time.

Do you understand?


On Thursday, January 19, 2017 at 1:34:30 AM UTC+9, [hidden email] wrote:
Iwao,

Issue #549 sounds like a sensible change. So, I modified my code as follows

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{account} and client_app = #{clientApp,typeHandler=com.loxcel.db.table.ClientAppTypeHandler} and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")
@Results( {
@Result(property="clientApp", column="client_app", typeHandler=ClientAppTypeHandler.class)
})
public Subscription selectCurrent (int account, ClientApp clientApp);


but I now get this exception:

### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'account' not found. Available parameters are [arg1, arg0, param1, param2]
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'account' not found. Available parameters are [arg1, arg0, param1, param2]"
2017-01-18 11:23:28.392,SEVERE,com.loxcel.util.net.webservice.IWebService,service,
org.apache.ibatis.exceptions.PersistenceException (
### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'account' not found. Available parameters are [arg1, arg0, param1, param2]
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'account' not found. Available parameters are [arg1, arg0, param1, param2]) was thrown from
          org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77)
          org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
          org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
          com.sun.proxy.$Proxy18.selectCurrent(Unknown Source)
          com.loxcel.backoffice.SubscriptionTxn.selectCurrent(SubscriptionTxn.java:84)


Now, if I change this one line

+ " WHERE account = #{account} and client_app = #{clientApp,typeHandler=com.loxcel.db.table.ClientAppTypeHandler} and now () between begin and expire"

to

+ " WHERE account = #{arg0} and client_app = #{arg1,typeHandler=com.loxcel.db.table.ClientAppTypeHandler} and now () between begin and expire"


all is ok and the program runs correctly.


However, I don't understand how the requirement to use #{arg0} is any better than #{0} ??


Thanks

Kevin


On Wednesday, January 11, 2017 at 7:37:06 PM UTC-5, k mac wrote:
Hello,

Yesterday, we upgraded from MyBatis 3.4.1 to 3.4.2. As a result, our Java code such as the following no longer works:

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{0} and client_app = #{1, typeHandler=com.loxcel.db.table.ClientAppTypeHandler} and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")

In order to comply with the changes made to 3.4.2, #{0} and #{1} from the code above must be replaced with #{arg0} and #{arg1}

Thus, in order for us to upgrade to 3.4.2 from 3.4.1 we will need to change a significant amount of code.

I doubt we're the only ones using MyBatis this way, so am I missing something or does 3.4.2 intentionally break a lot of existing code?

--
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.

--
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: Upgrade from Mybatis 3.4.1 to 3.4.2 breaks code that uses #{0}

k mac
In reply to this post by k mac
Iwao / Kazumi,

Thanks for the assistance. I am familiar with reflection.

However I might have stumbled upon a bug with MyBatis 3.4.2:

This code works with MyBatis 3.4.2, and demonstrates that the Java class files produced by my Eclipse installation contain sufficient information for reflection to work:

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{acctID} and client_app = 1 and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")
@Results( {
@Result(property="clientApp", column="client_app", typeHandler=ClientAppTypeHandler.class)
})
public Subscription selectCurrent (int acctID);


But this code, which only adds one formal parameter "caID", which is not referenced in the SELECT statement, generates an exception:

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{acctID} and client_app = 1 and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")
@Results( {
@Result(property="clientApp", column="client_app", typeHandler=ClientAppTypeHandler.class)
})
public Subscription selectCurrent (int acctID, int caID);


Details of the exception are here:

### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]"
2017-01-20 13:43:52.535,SEVERE,com.loxcel.util.net.webservice.IWebService,service,
org.apache.ibatis.exceptions.PersistenceException (
### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]) was thrown from
          org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77)
          org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
          org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
          com.sun.proxy.$Proxy18.selectCurrent(Unknown Source)
          com.loxcel.backoffice.SubscriptionTxn.selectCurrent(SubscriptionTxn.java:84)
          com.loxcel.auth.SignIn.webService(SignIn.java:136)
          com.loxcel.webservice.SignInWS.webService(SignInWS.java:47)
          com.loxcel.util.net.webservice.IWebService.service(IWebService.java:111)


And when I add a reference to "caID" within the SELECT statement as below

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{acctID} and client_app = #{caID} and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")
@Results( {
@Result(property="clientApp", column="client_app", typeHandler=ClientAppTypeHandler.class)
})
public Subscription selectCurrent (int acctID, int caID);


I receive this exception:

### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]"
2017-01-20 13:54:04.973,SEVERE,com.loxcel.util.net.webservice.IWebService,service,
org.apache.ibatis.exceptions.PersistenceException (
### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]) was thrown from
          org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77)
          org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
          org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
          com.sun.proxy.$Proxy18.selectCurrent(Unknown Source)
          com.loxcel.backoffice.SubscriptionTxn.selectCurrent(SubscriptionTxn.java:84)
          com.loxcel.auth.SignIn.webService(SignIn.java:136)
          com.loxcel.webservice.SignInWS.webService(SignInWS.java:47)
          com.loxcel.util.net.webservice.IWebService.service(IWebService.java:111)


Does this behavior suggest an issue with MyBatis?


Thanks again.

Kevin.



On Wednesday, January 11, 2017 at 7:37:06 PM UTC-5, k mac wrote:
Hello,

Yesterday, we upgraded from MyBatis 3.4.1 to 3.4.2. As a result, our Java code such as the following no longer works:

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{0} and client_app = #{1, typeHandler=com.loxcel.db.table.ClientAppTypeHandler} and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")

In order to comply with the changes made to 3.4.2, #{0} and #{1} from the code above must be replaced with #{arg0} and #{arg1}

Thus, in order for us to upgrade to 3.4.2 from 3.4.1 we will need to change a significant amount of code.

I doubt we're the only ones using MyBatis this way, so am I missing something or does 3.4.2 intentionally break a lot of existing code?


--
Thank you


Kevin Macdonald
Partner | Loxcel Geomatics
<a href="http://www.loxcel.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.loxcel.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFdch23wHqWmFtlZLjzt6Ckc6m6wg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.loxcel.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFdch23wHqWmFtlZLjzt6Ckc6m6wg&#39;;return true;">www.loxcel.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: Upgrade from Mybatis 3.4.1 to 3.4.2 breaks code that uses #{0}

Kazuki Shimizu
Hi Kevin,

Have you check the Iwao's comment ?

Iwao's comment:

If you are using Eclipse, you may need to enable 'Store information about method parameters' option in the Java Compiler setting. 

You can enable above compile option via check the "Preferences > Java > Compiler >>> Classfile Generation/Store information about method parameters (usable via reflection)"





























In my sample application(spring boot application), it work fine.

package com.example;


import org.apache.ibatis.annotations.Mapper;

import org.apache.ibatis.annotations.Select;

import org.springframework.boot.CommandLineRunner;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication

public class DemoApplication implements CommandLineRunner {

          public static void main(String[] args) {

               SpringApplication.run(DemoApplication.class, args);

       }


       
private final TestMapper testMapper;


        public DemoApplication(TestMapper testMapper) {

               this.testMapper = testMapper;

       }


       
@Override

       public void run(String... args) throws Exception {

               System.out.println(testMapper.calc(1, 1));

       }


        @Mapper

       public interface TestMapper {

               @Select("SELECT #{a} + #{b}")

               long calc(int a, int b);

       }

}




  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.3.RELEASE)

2017-01-21 07:53:00.552  INFO 17517 --- [           main] com.example.DemoApplication              : Starting DemoApplication on Kazuki-no-MacBook-Pro.local with PID 17517 (/Users/xxx/Documents/workspace-sts-3.8.3.RELEASE/demo/target/classes started by xxx in /Users/xxx/Documents/workspace-sts-3.8.3.RELEASE/demo)
2017-01-21 07:53:00.555  INFO 17517 --- [           main] com.example.DemoApplication              : No active profile set, falling back to default profiles: default
2017-01-21 07:53:00.594  INFO 17517 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@44a3ec6b: startup date [Sat Jan 21 07:53:00 JST 2017]; root of context hierarchy
2017-01-21 07:53:01.379  INFO 17517 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2
2017-01-21 07:53:01.536  INFO 17517 --- [           main] com.example.DemoApplication              : Started DemoApplication in 1.189 seconds (JVM running for 1.502)
2017-01-21 07:53:01.537  INFO 17517 --- [       Thread-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@44a3ec6b: startup date [Sat Jan 21 07:53:00 JST 2017]; root of context hierarchy
2017-01-21 07:53:01.538  INFO 17517 --- [       Thread-1] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown





On Saturday, January 21, 2017 at 3:58:43 AM UTC+9, [hidden email] wrote:
Iwao / Kazumi,

Thanks for the assistance. I am familiar with reflection.

However I might have stumbled upon a bug with MyBatis 3.4.2:

This code works with MyBatis 3.4.2, and demonstrates that the Java class files produced by my Eclipse installation contain sufficient information for reflection to work:

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{acctID} and client_app = 1 and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")
@Results( {
@Result(property="clientApp", column="client_app", typeHandler=ClientAppTypeHandler.class)
})
public Subscription selectCurrent (int acctID);


But this code, which only adds one formal parameter "caID", which is not referenced in the SELECT statement, generates an exception:

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{acctID} and client_app = 1 and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")
@Results( {
@Result(property="clientApp", column="client_app", typeHandler=ClientAppTypeHandler.class)
})
public Subscription selectCurrent (int acctID, int caID);


Details of the exception are here:

### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]"
2017-01-20 13:43:52.535,SEVERE,com.loxcel.util.net.webservice.IWebService,service,
org.apache.ibatis.exceptions.PersistenceException (
### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]) was thrown from
          org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77)
          org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
          org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
          com.sun.proxy.$Proxy18.selectCurrent(Unknown Source)
          com.loxcel.backoffice.SubscriptionTxn.selectCurrent(SubscriptionTxn.java:84)
          com.loxcel.auth.SignIn.webService(SignIn.java:136)
          com.loxcel.webservice.SignInWS.webService(SignInWS.java:47)
          com.loxcel.util.net.webservice.IWebService.service(IWebService.java:111)


And when I add a reference to "caID" within the SELECT statement as below

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{acctID} and client_app = #{caID} and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")
@Results( {
@Result(property="clientApp", column="client_app", typeHandler=ClientAppTypeHandler.class)
})
public Subscription selectCurrent (int acctID, int caID);


I receive this exception:

### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]"
2017-01-20 13:54:04.973,SEVERE,com.loxcel.util.net.webservice.IWebService,service,
org.apache.ibatis.exceptions.PersistenceException (
### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]) was thrown from
          org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77)
          org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
          org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
          com.sun.proxy.$Proxy18.selectCurrent(Unknown Source)
          com.loxcel.backoffice.SubscriptionTxn.selectCurrent(SubscriptionTxn.java:84)
          com.loxcel.auth.SignIn.webService(SignIn.java:136)
          com.loxcel.webservice.SignInWS.webService(SignInWS.java:47)
          com.loxcel.util.net.webservice.IWebService.service(IWebService.java:111)


Does this behavior suggest an issue with MyBatis?


Thanks again.

Kevin.



On Wednesday, January 11, 2017 at 7:37:06 PM UTC-5, k mac wrote:
Hello,

Yesterday, we upgraded from MyBatis 3.4.1 to 3.4.2. As a result, our Java code such as the following no longer works:

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{0} and client_app = #{1, typeHandler=com.loxcel.db.table.ClientAppTypeHandler} and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")

In order to comply with the changes made to 3.4.2, #{0} and #{1} from the code above must be replaced with #{arg0} and #{arg1}

Thus, in order for us to upgrade to 3.4.2 from 3.4.1 we will need to change a significant amount of code.

I doubt we're the only ones using MyBatis this way, so am I missing something or does 3.4.2 intentionally break a lot of existing code?


--
Thank you


Kevin Macdonald
Partner | Loxcel Geomatics
<a href="http://www.loxcel.com/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.loxcel.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFdch23wHqWmFtlZLjzt6Ckc6m6wg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.loxcel.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFdch23wHqWmFtlZLjzt6Ckc6m6wg&#39;;return true;">www.loxcel.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: Upgrade from Mybatis 3.4.1 to 3.4.2 breaks code that uses #{0}

Kazuki Shimizu
Hi Kevin,

Supplementally...
You can specify any variable-name as binding parameter(#{variable-name}) without -parameters option if your mapper method arguments is just one. 

e.g)
@Select("SELECT 'Hello' || #{name}")
String generateGreetingMessage(String s);

@Select("SELECT 'Hello' || #{value}")
String generateGreetingMessage(String s);

@Select("SELECT 'Hello' || #{s}")
String generateGreetingMessage(String s);

Above methods are work fine all.





On Saturday, January 21, 2017 at 8:15:28 AM UTC+9, Kazuki Shimizu wrote:
Hi Kevin,

Have you check the Iwao's comment ?

Iwao's comment:

If you are using Eclipse, you may need to enable 'Store information about method parameters' option in the Java Compiler setting. 

You can enable above compile option via check the "Preferences > Java > Compiler >>> Classfile Generation/Store information about method parameters (usable via reflection)"

<a href="https://lh3.googleusercontent.com/-Ib3iDuja1is/WIKYwqs-YgI/AAAAAAAAAIQ/x4xssGYfawQtJJINfLig8rmo5X6FZaFVgCLcB/s1600/sts-compiler-enable-parameters.png" style="clear:left;margin-bottom:1em;float:left;margin-right:1em" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://lh3.googleusercontent.com/-Ib3iDuja1is/WIKYwqs-YgI/AAAAAAAAAIQ/x4xssGYfawQtJJINfLig8rmo5X6FZaFVgCLcB/s1600/sts-compiler-enable-parameters.png&#39;;return true;" onclick="this.href=&#39;https://lh3.googleusercontent.com/-Ib3iDuja1is/WIKYwqs-YgI/AAAAAAAAAIQ/x4xssGYfawQtJJINfLig8rmo5X6FZaFVgCLcB/s1600/sts-compiler-enable-parameters.png&#39;;return true;">



























In my sample application(spring boot application), it work fine.

package com.example;


import org.apache.ibatis.annotations.Mapper;

import org.apache.ibatis.annotations.Select;

import org.springframework.boot.CommandLineRunner;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication

public class DemoApplication implements CommandLineRunner {

          public static void main(String[] args) {

               SpringApplication.run(DemoApplication.class, args);

       }


       
private final TestMapper testMapper;


        public DemoApplication(TestMapper testMapper) {

               this.testMapper = testMapper;

       }


       
@Override

       public void run(String... args) throws Exception {

               System.out.println(testMapper.calc(1, 1));

       }


        @Mapper

       public interface TestMapper {

               @Select("SELECT #{a} + #{b}")

               long calc(int a, int b);

       }

}




  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.3.RELEASE)

2017-01-21 07:53:00.552  INFO 17517 --- [           main] com.example.DemoApplication              : Starting DemoApplication on Kazuki-no-MacBook-Pro.local with PID 17517 (/Users/xxx/Documents/workspace-sts-3.8.3.RELEASE/demo/target/classes started by xxx in /Users/xxx/Documents/workspace-sts-3.8.3.RELEASE/demo)
2017-01-21 07:53:00.555  INFO 17517 --- [           main] com.example.DemoApplication              : No active profile set, falling back to default profiles: default
2017-01-21 07:53:00.594  INFO 17517 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@44a3ec6b: startup date [Sat Jan 21 07:53:00 JST 2017]; root of context hierarchy
2017-01-21 07:53:01.379  INFO 17517 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2
2017-01-21 07:53:01.536  INFO 17517 --- [           main] com.example.DemoApplication              : Started DemoApplication in 1.189 seconds (JVM running for 1.502)
2017-01-21 07:53:01.537  INFO 17517 --- [       Thread-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@44a3ec6b: startup date [Sat Jan 21 07:53:00 JST 2017]; root of context hierarchy
2017-01-21 07:53:01.538  INFO 17517 --- [       Thread-1] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown





On Saturday, January 21, 2017 at 3:58:43 AM UTC+9, [hidden email] wrote:
Iwao / Kazumi,

Thanks for the assistance. I am familiar with reflection.

However I might have stumbled upon a bug with MyBatis 3.4.2:

This code works with MyBatis 3.4.2, and demonstrates that the Java class files produced by my Eclipse installation contain sufficient information for reflection to work:

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{acctID} and client_app = 1 and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")
@Results( {
@Result(property="clientApp", column="client_app", typeHandler=ClientAppTypeHandler.class)
})
public Subscription selectCurrent (int acctID);


But this code, which only adds one formal parameter "caID", which is not referenced in the SELECT statement, generates an exception:

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{acctID} and client_app = 1 and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")
@Results( {
@Result(property="clientApp", column="client_app", typeHandler=ClientAppTypeHandler.class)
})
public Subscription selectCurrent (int acctID, int caID);


Details of the exception are here:

### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]"
2017-01-20 13:43:52.535,SEVERE,com.loxcel.util.net.webservice.IWebService,service,
org.apache.ibatis.exceptions.PersistenceException (
### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]) was thrown from
          org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77)
          org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
          org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
          com.sun.proxy.$Proxy18.selectCurrent(Unknown Source)
          com.loxcel.backoffice.SubscriptionTxn.selectCurrent(SubscriptionTxn.java:84)
          com.loxcel.auth.SignIn.webService(SignIn.java:136)
          com.loxcel.webservice.SignInWS.webService(SignInWS.java:47)
          com.loxcel.util.net.webservice.IWebService.service(IWebService.java:111)


And when I add a reference to "caID" within the SELECT statement as below

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{acctID} and client_app = #{caID} and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")
@Results( {
@Result(property="clientApp", column="client_app", typeHandler=ClientAppTypeHandler.class)
})
public Subscription selectCurrent (int acctID, int caID);


I receive this exception:

### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]"
2017-01-20 13:54:04.973,SEVERE,com.loxcel.util.net.webservice.IWebService,service,
org.apache.ibatis.exceptions.PersistenceException (
### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'acctID' not found. Available parameters are [arg1, arg0, param1, param2]) was thrown from
          org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
          org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77)
          org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
          org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
          com.sun.proxy.$Proxy18.selectCurrent(Unknown Source)
          com.loxcel.backoffice.SubscriptionTxn.selectCurrent(SubscriptionTxn.java:84)
          com.loxcel.auth.SignIn.webService(SignIn.java:136)
          com.loxcel.webservice.SignInWS.webService(SignInWS.java:47)
          com.loxcel.util.net.webservice.IWebService.service(IWebService.java:111)


Does this behavior suggest an issue with MyBatis?


Thanks again.

Kevin.



On Wednesday, January 11, 2017 at 7:37:06 PM UTC-5, k mac wrote:
Hello,

Yesterday, we upgraded from MyBatis 3.4.1 to 3.4.2. As a result, our Java code such as the following no longer works:

@Select(
  "SELECT id, created, account, client_app, begin, expire, payment, concurrent, seats, bump_secs"
+ " FROM subscription"
+ " WHERE account = #{0} and client_app = #{1, typeHandler=com.loxcel.db.table.ClientAppTypeHandler} and now () between begin and expire"
+ " ORDER BY created desc"
+ " LIMIT 1")

In order to comply with the changes made to 3.4.2, #{0} and #{1} from the code above must be replaced with #{arg0} and #{arg1}

Thus, in order for us to upgrade to 3.4.2 from 3.4.1 we will need to change a significant amount of code.

I doubt we're the only ones using MyBatis this way, so am I missing something or does 3.4.2 intentionally break a lot of existing code?


--
Thank you


Kevin Macdonald
Partner | Loxcel Geomatics
<a href="http://www.loxcel.com/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.loxcel.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFdch23wHqWmFtlZLjzt6Ckc6m6wg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.loxcel.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFdch23wHqWmFtlZLjzt6Ckc6m6wg&#39;;return true;">www.loxcel.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: Upgrade from Mybatis 3.4.1 to 3.4.2 breaks code that uses #{0}

k mac
"if your mapper method arguments is just one ..."

Aha! That explains why my code worked with one formal parameter but not with two formal parameters.

Still, is it a good idea to support "You can specify any variable-name as binding parameter" ??

The flag "Store information about method parameters" was set -- at the workspace level. But Eclipse for some reason had set "Enable project specific settings" which affected the project related to database transactions. And for that project, that flag was NOT set. So, that's why it wasn't working for me when I had two formal parameters.

The issue at hand has been resolved.

Thank you Iwao & Kazuki for the detailed instructions. Very helpful.


Kevin


On Friday, January 20, 2017 at 6:36:30 PM UTC-5, Kazuki Shimizu wrote:
Hi Kevin,

Supplementally...
You can specify any variable-name as binding parameter(#{variable-name}) without -parameters option if your mapper method arguments is just one. 

e.g)
@Select("SELECT 'Hello' || #{name}")
String generateGreetingMessage(String s);

@Select("SELECT 'Hello' || #{value}")
String generateGreetingMessage(String s);

@Select("SELECT 'Hello' || #{s}")
String generateGreetingMessage(String s);

Above methods are work fine all.





On Saturday, January 21, 2017 at 8:15:28 AM UTC+9, Kazuki Shimizu wrote:
Hi Kevin,

Have you check the Iwao's comment ?

Iwao's comment:

If you are using Eclipse, you may need to enable 'Store information about method parameters' option in the Java Compiler setting. 

You can enable above compile option via check the "Preferences > Java > Compiler >>> Classfile Generation/Store information about method parameters (usable via reflection)"

<a href="https://lh3.googleusercontent.com/-Ib3iDuja1is/WIKYwqs-YgI/AAAAAAAAAIQ/x4xssGYfawQtJJINfLig8rmo5X6FZaFVgCLcB/s1600/sts-compiler-enable-parameters.png" style="clear:left;margin-bottom:1em;float:left;margin-right:1em" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://lh3.googleusercontent.com/-Ib3iDuja1is/WIKYwqs-YgI/AAAAAAAAAIQ/x4xssGYfawQtJJINfLig8rmo5X6FZaFVgCLcB/s1600/sts-compiler-enable-parameters.png&#39;;return true;" onclick="this.href=&#39;https://lh3.googleusercontent.com/-Ib3iDuja1is/WIKYwqs-YgI/AAAAAAAAAIQ/x4xssGYfawQtJJINfLig8rmo5X6FZaFVgCLcB/s1600/sts-compiler-enable-parameters.png&#39;;return true;">



























In my sample application(spring boot application), it work fine.

package com.example;


import org.apache.ibatis.annotations.Mapper;

import org.apache.ibatis.annotations.Select;

import org.springframework.boot.CommandLineRunner;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication

public class DemoApplication implements CommandLineRunner {

          public static void main(String[] args) {

               SpringApplication.run(DemoApplication.class, args);

       }


       
private final TestMapper testMapper;


        public DemoApplication(TestMapper testMapper) {

               this.testMapper = testMapper;

       }


       
@Override

       public void run(String... args) throws Exception {

               System.out.println(testMapper.calc(1, 1));

       }


        @Mapper

       public interface TestMapper {

               @Select("SELECT #{a} + #{b}")

               long calc(int a, int b);

       }

}




  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.3.RELEASE)

2017-01-21 07:53:00.552  INFO 17517 --- [           main] com.example.DemoApplication              : Starting DemoApplication on Kazuki-no-MacBook-Pro.local with PID 17517 (/Users/xxx/Documents/workspace-sts-3.8.3.RELEASE/demo/target/classes started by xxx in /Users/xxx/Documents/workspace-sts-3.8.3.RELEASE/demo)
2017-01-21 07:53:00.555  INFO 17517 --- [           main] com.example.DemoApplication              : No active profile set, falling back to default profiles: default
2017-01-21 07:53:00.594  INFO 17517 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@44a3ec6b: startup date [Sat Jan 21 07:53:00 JST 2017]; root of context hierarchy
2017-01-21 07:53:01.379  INFO 17517 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2
2017-01-21 07:53:01.536  INFO 17517 --- [           main] com.example.DemoApplication              : Started DemoApplication in 1.189 seconds (JVM running for 1.502)
2017-01-21 07:53:01.537  INFO 17517 --- [       Thread-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@44a3ec6b: startup date [Sat Jan 21 07:53:00 JST 2017]; root of context hierarchy
2017-01-21 07:53:01.538  INFO 17517 --- [       Thread-1] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown

--
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: Upgrade from Mybatis 3.4.1 to 3.4.2 breaks code that uses #{0}

Kazuki Shimizu

> Still, is it a good idea to support "You can specify any variable-name as binding parameter" ??

I prefer to use -parameters option on JDK 8.
(I prefer to use @Param on JDK 7 or older. -> I use @Param on mapper method with multiple arguments)

Thanks.


On Saturday, January 21, 2017 at 9:43:14 AM UTC+9, [hidden email] wrote:
"if your mapper method arguments is just one ..."

Aha! That explains why my code worked with one formal parameter but not with two formal parameters.

Still, is it a good idea to support "You can specify any variable-name as binding parameter" ??

The flag "Store information about method parameters" was set -- at the workspace level. But Eclipse for some reason had set "Enable project specific settings" which affected the project related to database transactions. And for that project, that flag was NOT set. So, that's why it wasn't working for me when I had two formal parameters.

The issue at hand has been resolved.

Thank you Iwao & Kazuki for the detailed instructions. Very helpful.


Kevin


On Friday, January 20, 2017 at 6:36:30 PM UTC-5, Kazuki Shimizu wrote:
Hi Kevin,

Supplementally...
You can specify any variable-name as binding parameter(#{variable-name}) without -parameters option if your mapper method arguments is just one. 

e.g)
@Select("SELECT 'Hello' || #{name}")
String generateGreetingMessage(String s);

@Select("SELECT 'Hello' || #{value}")
String generateGreetingMessage(String s);

@Select("SELECT 'Hello' || #{s}")
String generateGreetingMessage(String s);

Above methods are work fine all.





On Saturday, January 21, 2017 at 8:15:28 AM UTC+9, Kazuki Shimizu wrote:
Hi Kevin,

Have you check the Iwao's comment ?

Iwao's comment:

If you are using Eclipse, you may need to enable 'Store information about method parameters' option in the Java Compiler setting. 

You can enable above compile option via check the "Preferences > Java > Compiler >>> Classfile Generation/Store information about method parameters (usable via reflection)"

<a href="https://lh3.googleusercontent.com/-Ib3iDuja1is/WIKYwqs-YgI/AAAAAAAAAIQ/x4xssGYfawQtJJINfLig8rmo5X6FZaFVgCLcB/s1600/sts-compiler-enable-parameters.png" style="clear:left;margin-bottom:1em;float:left;margin-right:1em" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://lh3.googleusercontent.com/-Ib3iDuja1is/WIKYwqs-YgI/AAAAAAAAAIQ/x4xssGYfawQtJJINfLig8rmo5X6FZaFVgCLcB/s1600/sts-compiler-enable-parameters.png&#39;;return true;" onclick="this.href=&#39;https://lh3.googleusercontent.com/-Ib3iDuja1is/WIKYwqs-YgI/AAAAAAAAAIQ/x4xssGYfawQtJJINfLig8rmo5X6FZaFVgCLcB/s1600/sts-compiler-enable-parameters.png&#39;;return true;">



























In my sample application(spring boot application), it work fine.

package com.example;


import org.apache.ibatis.annotations.Mapper;

import org.apache.ibatis.annotations.Select;

import org.springframework.boot.CommandLineRunner;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication

public class DemoApplication implements CommandLineRunner {

          public static void main(String[] args) {

               SpringApplication.run(DemoApplication.class, args);

       }


       
private final TestMapper testMapper;


        public DemoApplication(TestMapper testMapper) {

               this.testMapper = testMapper;

       }


       
@Override

       public void run(String... args) throws Exception {

               System.out.println(testMapper.calc(1, 1));

       }


        @Mapper

       public interface TestMapper {

               @Select("SELECT #{a} + #{b}")

               long calc(int a, int b);

       }

}




  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.3.RELEASE)

2017-01-21 07:53:00.552  INFO 17517 --- [           main] com.example.DemoApplication              : Starting DemoApplication on Kazuki-no-MacBook-Pro.local with PID 17517 (/Users/xxx/Documents/workspace-sts-3.8.3.RELEASE/demo/target/classes started by xxx in /Users/xxx/Documents/workspace-sts-3.8.3.RELEASE/demo)
2017-01-21 07:53:00.555  INFO 17517 --- [           main] com.example.DemoApplication              : No active profile set, falling back to default profiles: default
2017-01-21 07:53:00.594  INFO 17517 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@44a3ec6b: startup date [Sat Jan 21 07:53:00 JST 2017]; root of context hierarchy
2017-01-21 07:53:01.379  INFO 17517 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2
2017-01-21 07:53:01.536  INFO 17517 --- [           main] com.example.DemoApplication              : Started DemoApplication in 1.189 seconds (JVM running for 1.502)
2017-01-21 07:53:01.537  INFO 17517 --- [       Thread-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@44a3ec6b: startup date [Sat Jan 21 07:53:00 JST 2017]; root of context hierarchy
2017-01-21 07:53:01.538  INFO 17517 --- [       Thread-1] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown

--
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.