spring-mybatis

Spring with MyBatis: expected single matching bean but found 2

ぐ巨炮叔叔 提交于 2019-12-05 17:35:29
I've been using Spring with MyBatis and it's been working really well for a single database. I ran into difficulties when trying to add another database (see reproducible example on Github ). I'm using Spring Java configuration (i.e. not XML). Most of the examples I've seen show how to achieve this using XML. I have two data configuration classes (A & B) like this: @Configuration @MapperScan("io.woolford.database.mapper") public class DataConfigDatabaseA { @Bean(name="dataSourceA") public DataSource dataSourceA() throws SQLException { SimpleDriverDataSource dataSource = new

Spring Data JPA & MyBatis

荒凉一梦 提交于 2019-12-05 06:24:30
问题 I am trying to use Spring Data JPA with MyBatis. Since there isnt a Vendor Adapter for MyBatis, what is the alternative here? <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="packagesToScan" value="com.abc.xyz.domain"/> </bean> I am getting the below exception when I tried to initialize my application. Invocation of init method failed; nested exception is java.lang

Flush MyBatis Cache externally (outside of mapper)

血红的双手。 提交于 2019-12-04 14:40:12
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? I'm aware of @Options(flushCache=true) annotation, but this seems not to work outside of mapper

MyBatis with Guava multimap

孤人 提交于 2019-12-04 14:17:12
I want to use Guava multimap as a resultMap with MyBatis , to return a resultset that has a collection of several one to many entries, but I am not able to figure out the exact syntax for the same. Below is a sample of my table : +----+---------+----------+-------------+ | ID | PART_ID | NAME | PART_FAMILY | +----+---------+----------+-------------+ | 1 | 1 | bush | 300 | | 2 | 1 | a-bush | 300 | | 3 | 1 | 300-bush | 300 | | 4 | 2 | nut | 301 | +----+---------+----------+-------------+ I want a resultset such that I have a Guava multimap with PART_ID as the key, and NAME and PART_FAMILY as the

Spring Data JPA & MyBatis

眉间皱痕 提交于 2019-12-03 22:48:52
I am trying to use Spring Data JPA with MyBatis. Since there isnt a Vendor Adapter for MyBatis, what is the alternative here? <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="packagesToScan" value="com.abc.xyz.domain"/> </bean> I am getting the below exception when I tried to initialize my application. Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No PersistenceProvider specified in EntityManagerFactory configuration, and chosen

MyBatis how can I generate different sql for different database backend

孤街浪徒 提交于 2019-11-29 04:35:07
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 want to know is there any way that MyBatis can handle such a situation? (type of database differs in

Spring-boot with spring-mybatis - how to force it to logging all SQL queries

陌路散爱 提交于 2019-11-27 18:14:45
问题 I have a simple spring-boot-mybatis app (keep in mind, please). Mybatis is logging SQL queries only in case of failure (on excepions). Tell me please, how to force it to log all SQL query to console ? At this moment I am using slf4j logger (automatically configured by spring-boot ). I find this link: http://www.mybatis.org/mybatis-3/logging.html however I didnt manage to follow it. First of all configuration is shown for log4j , and I am not sure If I correctly understand: Is it sufficient to