spring-mybatis

How to use UUID type handler with @Many annotation in MyBatis?

大兔子大兔子 提交于 2021-01-28 01:12:59
问题 I`m using mybatis-spring-boot-starter with 2.1.0 version. And I need to process UUID type to get a nested collection. @Select("SELECT id, name FROM t_service s") @Results(value = { @Result(column = "id", property = "id", jdbcType = JdbcType.OTHER, typeHandler = UuidTypeHandler.class), @Result(column = "name", property = "name"), @Result(property = "rates", column = "id", javaType = List.class, many = @Many(select = "getAllRates")) }) List<Service> findAll(); @Select("SELECT date_from, date_to

MyBatis Cursor with Spring Boot

二次信任 提交于 2020-06-29 06:55:25
问题 I'm trying to use a MyBatis Cursor with Spring Boot to iterate a large query: Mapper: @Mapper @Repository interface UserMapper { @Select("SELECT * FROM huge_user_table") Cursor<User> getUsers(); Consumer: @Component public class UserProcessor { @Autowired private UserMapper userMapper; public boolean process() throws IOException { Cursor<User> users = userMapper.getUsers(); //users.isOpen() == false for (User user : users) { //Never iterates System.out.println(user.getId()); } When I get my

Transaction on two tables at the same time in two different databases

旧巷老猫 提交于 2020-01-14 05:57:08
问题 I have spring-boot app with mybatis as my ORM. I also use sqlserver 2012 . I consider following scenario: void foo () { set current datasource as Datasource D1 (connected to database D1) do some insert on table T1 in database D1 set current datasource as Datasource D2 (connected to database D2) do some insert on table T1 (the same name) in database D2 } I would like to be able to ensure that it always succees both queries. Otherwise (when at least one of them fails) transaction will be

MyBatis ORA-01745: invalid host/bind variable name

只愿长相守 提交于 2019-12-25 06:59:45
问题 I have an insert statement in MyBatis using Oracle 11g R2 on the backend with the Oracle ojdbc6 driver. I am repeatedly getting java.sql.SQLSyntaxErrorException: ORA-01745: invalid host/bind variable name However I don't see what is causing the issue, I'm not using any Oracle reserved Keywords. <insert id="createRecord" parameterType="org.appliication.core.domain.TRRecord" statementType="PREPARED" useGeneratedKeys="true" keyColumn="ID" keyProperty="id"> INSERT INTO T_TR_PUBLICATION p ( p.TR

Spring 4 + MyBatis integration issue using Java 8

旧街凉风 提交于 2019-12-24 04:25:13
问题 I'm facing the following exception when using Java 8 (1.8.0_60), Spring 4.2.1 and MyBatis 3.3.0 Sep 29, 2015 11:02:58 AM org.springframework.context.annotation.AnnotationConfigApplicationContext prepareRefresh INFO: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@246b179d: startup date [Tue Sep 29 11:02:58 EDT 2015]; root of context hierarchy Sep 29, 2015 11:02:58 AM org.mybatis.spring.mapper.ClassPathMapperScanner checkCandidate WARNING: Skipping

MyBatis - jdbcTypeForNull Oracle

好久不见. 提交于 2019-12-23 11:54:55
问题 I am using MyBatis with an Oracle 11g R2 database. I am using MyBatis 3.3 with ojdbc6 12.1.0.2. My issue is whenever I tried to insert an object that is null I get the following. org.springframework.jdbc.UncategorizedSQLException: Error setting null for parameter #8 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: Invalid column type: 1111 My understanding is in the latest version of

Performance issue while inserting 2000 records using mybatis(3.2.8 version)

心不动则不痛 提交于 2019-12-23 05:11:34
问题 I am trying to insert 2000 records in Employee table in batch (using mybatis). My requirements are: 1. To log the error if any of the record fails to insert. 2. To continue with the insertion even if any one of the record fails. 3. Rollback should not happen for other if any one of the record fails. 4. Good performance. Sample code of Dao implementation: Here I have come up with 2 scenarios. Calling sqlSession.commit() outside the loop. SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory

Get the data which is inserted using @Transactional in the same transaction

房东的猫 提交于 2019-12-22 01:24:28
问题 I am inserting the data in one method(has @Transactional(propagation = Propagation.Required) ) but in the other method(has @Transactional(propagation = Propagation.Required) ) if I try to get the same data it is giving null. Both methods are wrote in service layer with @Transactional (rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) How to get the data which is inserted in the same transaction. Something like :- @Service public class Service{ @Transactional public void

Flush MyBatis Cache externally (outside of mapper)

六眼飞鱼酱① 提交于 2019-12-21 21:52:39
问题 I'm using MyBatis with second level cache activated via <cache/> in xml mapper files. Suppose I want to interact with the underlying DB/DataSource decoupled from MyBatis, for instance via direct jdbcTemplate. How can I assure, that the MyBatis cache gets flushed appropriateley when I Insert/Update/Delete via jdbcTemplate on a table for that MyBatis holds cached query results. In other words, how can I force MyBatis to flush its cache from outside of MyBatis mappers for certain cache namespace

MyBatis how can I generate different sql for different database backend

倾然丶 夕夏残阳落幕 提交于 2019-12-18 04:17:21
问题 I'm using mybatis-spring 1.2.3 together with Spring4 to create a web application. The main data storage is MySQL in production environment, but I also use in-memory database H2 in unit testing. MyBatis works well with both of MySQL and H2 in testing and production, but I come across a problem that one day I need to use force index(idx1) in a query to MySQL, which will cause a syntax error in unit testing as H2 hasn't supported force index . As the result, the unit testing is totally broken. I