MyBatis Spring Boot custom type handler











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();
}









share|improve this question









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















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();
}









share|improve this question









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













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();
}









share|improve this question









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






share|improve this question









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.











share|improve this question









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.









share|improve this question




share|improve this question








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


















  • 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












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.






share|improve this answer























  • 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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Alex Lybetsky is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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
































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.






share|improve this answer























  • 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















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.






share|improve this answer























  • 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













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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








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


















  • 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










Alex Lybetsky is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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.















 


draft saved


draft discarded














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




















































































Popular posts from this blog

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff