MyBatis Spring Boot custom type handler

Multi tool use
up vote
0
down vote
favorite
I need help with Spring Boot and MyBatis integration. I have an issue with custom BaseTypeHandler. I've created a mapper:
@MappedTypes({LocalDateTime.class})
public class LocalDateTimeHandler extends BaseTypeHandler<LocalDateTime> {
I've added a type handler:
sqlSessionFactory.setTypeHandlers(new LocalDateTimeHandler{new LocalDateTimeHandler()});
And I have next error:
org.apache.ibatis.executor.ExecutorException: No constructor found in com.some.space.SomeObject matching [java.lang.Integer, java.sql.Timestamp, java.sql.Timestamp]
Where SomeObject looks like:
public class SomeObject {
private Long id;
private LocalDateTime created;
private LocalDateTime updated;
public SomeObject(Integer id, LocalDateTime created, LocalDateTime updated){
//..........
}
}
I using mybatis-spring and spring-boot-starter-web version 1.3.2.
All examples about working with TypeHandlers are on the XML configuration, but I need to use Java configs way. What I'm doing wrong?
UPD:
My mapper:
@Component
@Mapper
public interface SomeObjectRepository {
@Select("SELECT * FROM some_objects")
@Results(value = {
@Result(property = "created", column = "created_date", typeHandler = LocalDateTimeTypeHandler.class, jdbcType = JdbcType.TIMESTAMP),
@Result(property = "updated", column = "updated_date", typeHandler = LocalDateTimeTypeHandler.class, jdbcType = JdbcType.TIMESTAMP)
})
List<SomeObject> getAll();
}
mybatis spring-mybatis
New contributor
Alex Lybetsky is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
I need help with Spring Boot and MyBatis integration. I have an issue with custom BaseTypeHandler. I've created a mapper:
@MappedTypes({LocalDateTime.class})
public class LocalDateTimeHandler extends BaseTypeHandler<LocalDateTime> {
I've added a type handler:
sqlSessionFactory.setTypeHandlers(new LocalDateTimeHandler{new LocalDateTimeHandler()});
And I have next error:
org.apache.ibatis.executor.ExecutorException: No constructor found in com.some.space.SomeObject matching [java.lang.Integer, java.sql.Timestamp, java.sql.Timestamp]
Where SomeObject looks like:
public class SomeObject {
private Long id;
private LocalDateTime created;
private LocalDateTime updated;
public SomeObject(Integer id, LocalDateTime created, LocalDateTime updated){
//..........
}
}
I using mybatis-spring and spring-boot-starter-web version 1.3.2.
All examples about working with TypeHandlers are on the XML configuration, but I need to use Java configs way. What I'm doing wrong?
UPD:
My mapper:
@Component
@Mapper
public interface SomeObjectRepository {
@Select("SELECT * FROM some_objects")
@Results(value = {
@Result(property = "created", column = "created_date", typeHandler = LocalDateTimeTypeHandler.class, jdbcType = JdbcType.TIMESTAMP),
@Result(property = "updated", column = "updated_date", typeHandler = LocalDateTimeTypeHandler.class, jdbcType = JdbcType.TIMESTAMP)
})
List<SomeObject> getAll();
}
mybatis spring-mybatis
New contributor
Alex Lybetsky is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Please, show the mapping you are using.
– Roman Konoval
Nov 8 at 15:01
Thanks. I've update a main message.
– Alex Lybetsky
Nov 9 at 6:33
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I need help with Spring Boot and MyBatis integration. I have an issue with custom BaseTypeHandler. I've created a mapper:
@MappedTypes({LocalDateTime.class})
public class LocalDateTimeHandler extends BaseTypeHandler<LocalDateTime> {
I've added a type handler:
sqlSessionFactory.setTypeHandlers(new LocalDateTimeHandler{new LocalDateTimeHandler()});
And I have next error:
org.apache.ibatis.executor.ExecutorException: No constructor found in com.some.space.SomeObject matching [java.lang.Integer, java.sql.Timestamp, java.sql.Timestamp]
Where SomeObject looks like:
public class SomeObject {
private Long id;
private LocalDateTime created;
private LocalDateTime updated;
public SomeObject(Integer id, LocalDateTime created, LocalDateTime updated){
//..........
}
}
I using mybatis-spring and spring-boot-starter-web version 1.3.2.
All examples about working with TypeHandlers are on the XML configuration, but I need to use Java configs way. What I'm doing wrong?
UPD:
My mapper:
@Component
@Mapper
public interface SomeObjectRepository {
@Select("SELECT * FROM some_objects")
@Results(value = {
@Result(property = "created", column = "created_date", typeHandler = LocalDateTimeTypeHandler.class, jdbcType = JdbcType.TIMESTAMP),
@Result(property = "updated", column = "updated_date", typeHandler = LocalDateTimeTypeHandler.class, jdbcType = JdbcType.TIMESTAMP)
})
List<SomeObject> getAll();
}
mybatis spring-mybatis
New contributor
Alex Lybetsky is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I need help with Spring Boot and MyBatis integration. I have an issue with custom BaseTypeHandler. I've created a mapper:
@MappedTypes({LocalDateTime.class})
public class LocalDateTimeHandler extends BaseTypeHandler<LocalDateTime> {
I've added a type handler:
sqlSessionFactory.setTypeHandlers(new LocalDateTimeHandler{new LocalDateTimeHandler()});
And I have next error:
org.apache.ibatis.executor.ExecutorException: No constructor found in com.some.space.SomeObject matching [java.lang.Integer, java.sql.Timestamp, java.sql.Timestamp]
Where SomeObject looks like:
public class SomeObject {
private Long id;
private LocalDateTime created;
private LocalDateTime updated;
public SomeObject(Integer id, LocalDateTime created, LocalDateTime updated){
//..........
}
}
I using mybatis-spring and spring-boot-starter-web version 1.3.2.
All examples about working with TypeHandlers are on the XML configuration, but I need to use Java configs way. What I'm doing wrong?
UPD:
My mapper:
@Component
@Mapper
public interface SomeObjectRepository {
@Select("SELECT * FROM some_objects")
@Results(value = {
@Result(property = "created", column = "created_date", typeHandler = LocalDateTimeTypeHandler.class, jdbcType = JdbcType.TIMESTAMP),
@Result(property = "updated", column = "updated_date", typeHandler = LocalDateTimeTypeHandler.class, jdbcType = JdbcType.TIMESTAMP)
})
List<SomeObject> getAll();
}
mybatis spring-mybatis
mybatis spring-mybatis
New contributor
Alex Lybetsky is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Alex Lybetsky is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Nov 9 at 6:33
New contributor
Alex Lybetsky is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Nov 8 at 10:01
Alex Lybetsky
11
11
New contributor
Alex Lybetsky is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Alex Lybetsky is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Alex Lybetsky is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Please, show the mapping you are using.
– Roman Konoval
Nov 8 at 15:01
Thanks. I've update a main message.
– Alex Lybetsky
Nov 9 at 6:33
add a comment |
Please, show the mapping you are using.
– Roman Konoval
Nov 8 at 15:01
Thanks. I've update a main message.
– Alex Lybetsky
Nov 9 at 6:33
Please, show the mapping you are using.
– Roman Konoval
Nov 8 at 15:01
Please, show the mapping you are using.
– Roman Konoval
Nov 8 at 15:01
Thanks. I've update a main message.
– Alex Lybetsky
Nov 9 at 6:33
Thanks. I've update a main message.
– Alex Lybetsky
Nov 9 at 6:33
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You haven't instructed mybatis to use your type handler for timestamp fields. So it converts timestamp fields from the database using default type handler for that JDBC type.
If you want to do this only in some queries do like this for xml mapping:
<result property="created" column="created"
typeHandler="com.mycompany.myapp.LocalDateTimeHandler"/>
Or via annotations:
@Result(property = "created", column = "created",
typeHandler=LocalDateTimeHandler.class)
If you want to make it global and use it for all fields of the specific JDBC type add @MappedJdbcTypes
to you TypeHandler
:
@MappedJdbcTypes({JdbcType.TIMESTAMP})
@MappedTypes({LocalDateTime.class})
public class LocalDateTimeHandler extends BaseTypeHandler<LocalDateTime> {
Depending on the version of mybatis you are using you may need to set includeNullJdbcType=true
on the @MappedJdbcTypes
annotation.
See documentation for details about this.
Thank you for your response. But it doesn't work in my case. The MyBatis trying to use constructor with (Integer, Timestamp, Timestamp).
– Alex Lybetsky
Nov 8 at 13:19
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You haven't instructed mybatis to use your type handler for timestamp fields. So it converts timestamp fields from the database using default type handler for that JDBC type.
If you want to do this only in some queries do like this for xml mapping:
<result property="created" column="created"
typeHandler="com.mycompany.myapp.LocalDateTimeHandler"/>
Or via annotations:
@Result(property = "created", column = "created",
typeHandler=LocalDateTimeHandler.class)
If you want to make it global and use it for all fields of the specific JDBC type add @MappedJdbcTypes
to you TypeHandler
:
@MappedJdbcTypes({JdbcType.TIMESTAMP})
@MappedTypes({LocalDateTime.class})
public class LocalDateTimeHandler extends BaseTypeHandler<LocalDateTime> {
Depending on the version of mybatis you are using you may need to set includeNullJdbcType=true
on the @MappedJdbcTypes
annotation.
See documentation for details about this.
Thank you for your response. But it doesn't work in my case. The MyBatis trying to use constructor with (Integer, Timestamp, Timestamp).
– Alex Lybetsky
Nov 8 at 13:19
add a comment |
up vote
0
down vote
You haven't instructed mybatis to use your type handler for timestamp fields. So it converts timestamp fields from the database using default type handler for that JDBC type.
If you want to do this only in some queries do like this for xml mapping:
<result property="created" column="created"
typeHandler="com.mycompany.myapp.LocalDateTimeHandler"/>
Or via annotations:
@Result(property = "created", column = "created",
typeHandler=LocalDateTimeHandler.class)
If you want to make it global and use it for all fields of the specific JDBC type add @MappedJdbcTypes
to you TypeHandler
:
@MappedJdbcTypes({JdbcType.TIMESTAMP})
@MappedTypes({LocalDateTime.class})
public class LocalDateTimeHandler extends BaseTypeHandler<LocalDateTime> {
Depending on the version of mybatis you are using you may need to set includeNullJdbcType=true
on the @MappedJdbcTypes
annotation.
See documentation for details about this.
Thank you for your response. But it doesn't work in my case. The MyBatis trying to use constructor with (Integer, Timestamp, Timestamp).
– Alex Lybetsky
Nov 8 at 13:19
add a comment |
up vote
0
down vote
up vote
0
down vote
You haven't instructed mybatis to use your type handler for timestamp fields. So it converts timestamp fields from the database using default type handler for that JDBC type.
If you want to do this only in some queries do like this for xml mapping:
<result property="created" column="created"
typeHandler="com.mycompany.myapp.LocalDateTimeHandler"/>
Or via annotations:
@Result(property = "created", column = "created",
typeHandler=LocalDateTimeHandler.class)
If you want to make it global and use it for all fields of the specific JDBC type add @MappedJdbcTypes
to you TypeHandler
:
@MappedJdbcTypes({JdbcType.TIMESTAMP})
@MappedTypes({LocalDateTime.class})
public class LocalDateTimeHandler extends BaseTypeHandler<LocalDateTime> {
Depending on the version of mybatis you are using you may need to set includeNullJdbcType=true
on the @MappedJdbcTypes
annotation.
See documentation for details about this.
You haven't instructed mybatis to use your type handler for timestamp fields. So it converts timestamp fields from the database using default type handler for that JDBC type.
If you want to do this only in some queries do like this for xml mapping:
<result property="created" column="created"
typeHandler="com.mycompany.myapp.LocalDateTimeHandler"/>
Or via annotations:
@Result(property = "created", column = "created",
typeHandler=LocalDateTimeHandler.class)
If you want to make it global and use it for all fields of the specific JDBC type add @MappedJdbcTypes
to you TypeHandler
:
@MappedJdbcTypes({JdbcType.TIMESTAMP})
@MappedTypes({LocalDateTime.class})
public class LocalDateTimeHandler extends BaseTypeHandler<LocalDateTime> {
Depending on the version of mybatis you are using you may need to set includeNullJdbcType=true
on the @MappedJdbcTypes
annotation.
See documentation for details about this.
edited Nov 8 at 11:04
answered Nov 8 at 10:58
Roman Konoval
7,31211931
7,31211931
Thank you for your response. But it doesn't work in my case. The MyBatis trying to use constructor with (Integer, Timestamp, Timestamp).
– Alex Lybetsky
Nov 8 at 13:19
add a comment |
Thank you for your response. But it doesn't work in my case. The MyBatis trying to use constructor with (Integer, Timestamp, Timestamp).
– Alex Lybetsky
Nov 8 at 13:19
Thank you for your response. But it doesn't work in my case. The MyBatis trying to use constructor with (Integer, Timestamp, Timestamp).
– Alex Lybetsky
Nov 8 at 13:19
Thank you for your response. But it doesn't work in my case. The MyBatis trying to use constructor with (Integer, Timestamp, Timestamp).
– Alex Lybetsky
Nov 8 at 13:19
add a comment |
Alex Lybetsky is a new contributor. Be nice, and check out our Code of Conduct.
Alex Lybetsky is a new contributor. Be nice, and check out our Code of Conduct.
Alex Lybetsky is a new contributor. Be nice, and check out our Code of Conduct.
Alex Lybetsky is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205366%2fmybatis-spring-boot-custom-type-handler%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
5o wGOwu,jtTPKOIZm,mZXeAxA04yGLOq 73oQ6fTwdC,a7Q 7y57 MO 3Rk1t1pgpq
Please, show the mapping you are using.
– Roman Konoval
Nov 8 at 15:01
Thanks. I've update a main message.
– Alex Lybetsky
Nov 9 at 6:33