Select and EnumOrdinalTypeHandler works, but Insert is using the name of the enum ?

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

Select and EnumOrdinalTypeHandler works, but Insert is using the name of the enum ?

BakaOnigiri
Hi,

I have a little problem, I am using a xml type mapper the describe a property as handled by the EnumOrdinalTypeHandler.

For all of my select, it works great.


But now I have to write an insert, and the translated parameter is the string of the enum name, not the enum ordinal value.

Could this be linked to the fact that for this select I am passing the entity instance ?

Traces :


14:36:13.104 904293 [ProcessClient-Pool-Thread-6] DEBUG org.apache.ibatis.logging.jdbc.BaseJdbcLogger - ==> Parameters: Foo(String), ANALOGIC(String)
14:36:13.105 904294 [ProcessClient-Pool-Thread-6] DEBUG org.apache.ibatis.transaction.jdbc.JdbcTransaction - Closing JDBC Connection [HikariProxyConnection@538251654 wrapping org.postgresql.jdbc.PgConnection@16732807]
14:36:13.106 904295 [ProcessClient-Pool-Thread-6] ERROR com.test.AdminChannelProcessor - Error during channel creation
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: invalid input syntax for integer: "ANALOGIC"
### The error may involve com.test.db.mappers.ChannelMapper.create-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO             channels (                   name,                   type                 )         VALUES             (                 ?,                 ?            )
### Cause: org.postgresql.util.PSQLException: ERROR: invalid input syntax for integer: "ANALOGIC"
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200)



Extract of my mapper :

<mapper namespace='com.test.db.mappers.ChannelMapper'>
<resultMap type='Channel' id='ChannelResult'>
<id property='id' column='id' />
<result property='name' column='name' />
<result property='type' column='type' typeHandler="org.apache.ibatis.type.EnumOrdinalTypeHandler" />
</resultMap>

<!-- this select works well, the ordinal value in the database is converted to enum entry -->
 
<select id='getOne' resultMap='ChannelResult'>
SELECT
*
FROM
recorder.channels
WHERE
id = #{id}
</select>

<!-- here the value passed to the database is the string value of the enum -->
 <insert id="create" parameterType="Channel" keyColumn="id">
INSERT INTO
channels (
name,
type,
)
VALUES
(
#{cEnt.name},
#{cEnt.type}
)
</insert>
</mapper>

--
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: Select and EnumOrdinalTypeHandler works, but Insert is using the name of the enum ?

Kazuki Shimizu
Please try #{cEnt.type,typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler}.



On Monday, April 16, 2018 at 9:39:17 PM UTC+9, BakaOnigiri wrote:
Hi,

I have a little problem, I am using a xml type mapper the describe a property as handled by the EnumOrdinalTypeHandler.

For all of my select, it works great.


But now I have to write an insert, and the translated parameter is the string of the enum name, not the enum ordinal value.

Could this be linked to the fact that for this select I am passing the entity instance ?

Traces :


14:36:13.104 904293 [ProcessClient-Pool-Thread-6] DEBUG org.apache.ibatis.logging.jdbc.BaseJdbcLogger - ==> Parameters: Foo(String), ANALOGIC(String)
14:36:13.105 904294 [ProcessClient-Pool-Thread-6] DEBUG org.apache.ibatis.transaction.jdbc.JdbcTransaction - Closing JDBC Connection [HikariProxyConnection@538251654 wrapping org.postgresql.jdbc.PgConnection@16732807]
14:36:13.106 904295 [ProcessClient-Pool-Thread-6] ERROR com.test.AdminChannelProcessor - Error during channel creation
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: invalid input syntax for integer: "ANALOGIC"
### The error may involve com.test.db.mappers.ChannelMapper.create-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO             channels (                   name,                   type                 )         VALUES             (                 ?,                 ?            )
### Cause: org.postgresql.util.PSQLException: ERROR: invalid input syntax for integer: "ANALOGIC"
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200)



Extract of my mapper :

<mapper namespace='com.test.db.mappers.ChannelMapper'>
<resultMap type='Channel' id='ChannelResult'>
<id property='id' column='id' />
<result property='name' column='name' />
<result property='type' column='type' typeHandler="org.apache.ibatis.type.EnumOrdinalTypeHandler" />
</resultMap>

<!-- this select works well, the ordinal value in the database is converted to enum entry -->
 
<select id='getOne' resultMap='ChannelResult'>
SELECT
*
FROM
recorder.channels
WHERE
id = #{id}
</select>

<!-- here the value passed to the database is the string value of the enum -->
 <insert id="create" parameterType="Channel" keyColumn="id">
INSERT INTO
channels (
name,
type,
)
VALUES
(
#{cEnt.name},
#{cEnt.type}
)
</insert>
</mapper>

--
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: Select and EnumOrdinalTypeHandler works, but Insert is using the name of the enum ?

BakaOnigiri
I tried that, the the xml mapper is not loaded because the EnumOrdinalTypeHandler don't have a default constructor without parameter.

I finally how to solve my problem. In fact I must not use the EnumOrdinalTypeHandler type handler, I have to create a custom enum type handler class that extends EnumOrdinalTypeHandler.

 
Le lundi 16 avril 2018 17:31:14 UTC+2, Kazuki Shimizu a écrit :
Please try #{cEnt.type,typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler}.

For details, please refer to <a href="http://www.mybatis.org/mybatis-3/sqlmap-xml.html#Parameters" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.mybatis.org%2Fmybatis-3%2Fsqlmap-xml.html%23Parameters\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHYqTTXZ7kcqY7CVJ5bEPTHc5jcHg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.mybatis.org%2Fmybatis-3%2Fsqlmap-xml.html%23Parameters\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHYqTTXZ7kcqY7CVJ5bEPTHc5jcHg&#39;;return true;">http://www.mybatis.org/mybatis-3/sqlmap-xml.html#Parameters.


On Monday, April 16, 2018 at 9:39:17 PM UTC+9, BakaOnigiri wrote:
Hi,

I have a little problem, I am using a xml type mapper the describe a property as handled by the EnumOrdinalTypeHandler.

For all of my select, it works great.


But now I have to write an insert, and the translated parameter is the string of the enum name, not the enum ordinal value.

Could this be linked to the fact that for this select I am passing the entity instance ?

Traces :


14:36:13.104 904293 [ProcessClient-Pool-Thread-6] DEBUG org.apache.ibatis.logging.jdbc.BaseJdbcLogger - ==> Parameters: Foo(String), ANALOGIC(String)
14:36:13.105 904294 [ProcessClient-Pool-Thread-6] DEBUG org.apache.ibatis.transaction.jdbc.JdbcTransaction - Closing JDBC Connection [HikariProxyConnection@538251654 wrapping org.postgresql.jdbc.PgConnection@16732807]
14:36:13.106 904295 [ProcessClient-Pool-Thread-6] ERROR com.test.AdminChannelProcessor - Error during channel creation
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: invalid input syntax for integer: "ANALOGIC"
### The error may involve com.test.db.mappers.ChannelMapper.create-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO             channels (                   name,                   type                 )         VALUES             (                 ?,                 ?            )
### Cause: org.postgresql.util.PSQLException: ERROR: invalid input syntax for integer: "ANALOGIC"
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200)



Extract of my mapper :

<mapper namespace='com.test.db.mappers.ChannelMapper'>
<resultMap type='Channel' id='ChannelResult'>
<id property='id' column='id' />
<result property='name' column='name' />
<result property='type' column='type' typeHandler="org.apache.ibatis.type.EnumOrdinalTypeHandler" />
</resultMap>

<!-- this select works well, the ordinal value in the database is converted to enum entry -->
 
<select id='getOne' resultMap='ChannelResult'>
SELECT
*
FROM
recorder.channels
WHERE
id = #{id}
</select>

<!-- here the value passed to the database is the string value of the enum -->
 <insert id="create" parameterType="Channel" keyColumn="id">
INSERT INTO
channels (
name,
type,
)
VALUES
(
#{cEnt.name},
#{cEnt.type}
)
</insert>
</mapper>

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