Code Monkey home page Code Monkey logo

spring's Introduction

MyBatis Spring Adapter

Java CI Coverage Status Maven central Sonatype Nexus (Snapshots) License

mybatis-spring

MyBatis-Spring adapter is an easy-to-use Spring Framework bridge for MyBatis sql mapping framework.

Supported Versions

  • master - Support for Spring 6 and Spring Batch 5
  • 2.1.x - Maintenance for Spring 5 and Spring Batch 4

Essentials

spring's People

Contributors

arykov avatar bfss avatar chenqimiao avatar codeingboy avatar dengchuanbio avatar dependabot-preview[bot] avatar dependabot[bot] avatar eddumelendez avatar emacarron avatar evans810 avatar fanofxiaofeng avatar galcyurio avatar gdarmont avatar happysca avatar harawata avatar hazendaz avatar hboutemy avatar hpresnall avatar jeffgbutler avatar kangzhidong avatar kazuki43zoo avatar mr-serjey avatar nmaves avatar pboonphong avatar raison95 avatar renovate[bot] avatar runrioter avatar simonetripodi avatar tacoo avatar ylyxf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spring's Issues

JDBC Connetion will not be managed by Spring (from mybatis)

@emacarron, we encountered transaction not enabled or detected with mybatis-spring. and please spare your time and take a look at issue at spring jira: https://jira.spring.io/browse/SPR-12564

as the spring team suggestion, he suggested me handle such thing at mybatis-spring. the reason for such was originated from mybatis-spring class:SpringManagedTransaction.java while it checked whether the connection was around transaction or not relied on DataSourceUtils.isConnectionTransactional(connection,datasource) from spring jdbc.

to my surprise, when everything configured as mybatis and spring suggestion, the calling for the above method returned false which induced the result for JDBC connetion will not be managed by spring. things confused me a lot for a long period of time and I hope you could solve such problem or help me locate where the problem.

dynamic datasource issue

I have some Idea about mybatis + spring. Now, My team Dev with spring + mybatis, the problem is , there are more than one datasource, and I need to change them in program.
The matter comed ! As we know, dev with mybatis + spring need mybatis-spring.jar. so the spring dynamic datasource(extends AbstractRoutingDataSource ) not worked.

So I have to override SqlSessionTemplate, so I done something like below:


public class EjsSqlSessionTemplate extends SqlSessionTemplate {

private Map<Object, SqlSessionFactory> targetSqlSessionFactory;

public void setTargetSqlSessionFactory(Map<Object, SqlSessionFactory> targetSqlSessionFactory) {
    this.targetSqlSessionFactory = targetSqlSessionFactory;
}

@OverRide
public SqlSessionFactory getSqlSessionFactory() {

    SqlSessionFactory targetSqlSessionFactory = this.targetSqlSessionFactory.get(SqlSessionContextHolder.getDataSourceKey());
    if (targetSqlSessionFactory != null) {
        return targetSqlSessionFactory;
    } else if ( this.sqlSessionFactory != null) {
        return  this.sqlSessionFactory;
    }
   throw new IllegalArgumentException("sqlSessionFactory or targetSqlSessionFactory must set one at least");
}

@Override
public Configuration getConfiguration() {
    return this.getSqlSessionFactory().getConfiguration();
}

}

##

As you see , I try to make the SqlSessionFactory dynamic in SqlSessionTemplate 。But you know, the sqlSessionProxy produce by SqlSessionInterceptor in SqlSessionTemplate.
the code like this( in SqlSessionTemplate.java line:349)

final SqlSession sqlSession = getSqlSession(
SqlSessionTemplate.this.sqlSessionFactory,
SqlSessionTemplate.this.executorType,
SqlSessionTemplate.this.exceptionTranslator);

the first arg sqlSessionFactory, you are read from field. but the field was init during spring context start. So I can change the sqlSessionFactory although I override the method named getSqlSessionFactory()

so, I have to copy all of the code in SqlSessionTemplate。 and just modify a few method in the class. I think It is not the best way to do this. If you modify the SqlSessionInterceptor
. let it get sqlSessionFactory by getSqlSessionFactory() method, It will be nice. I just need to override getSqlSessionFactory() method with my strategy,then can change datasource easyly. Do you think so ?

My english is bad. If you can read china, I want to see the problem desc in my blog. the url is : http://blog.csdn.net/zl3450341/article/details/20150687

mybatis + spring use aop:pointcut not rollback

i fond that config mybatis transaction whith spring can only be used tx:annotation-driven,
if use config like this, the transaction will be not rollback

      <tx:advice id="transactionAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="add*" propagation="REQUIRED"/>
        <tx:method name="save*" propagation="REQUIRED"/>
        <tx:method name="upd*" propagation="REQUIRED"/>
        <tx:method name="update*" propagation="REQUIRED"/>
        <tx:method name="modify*" propagation="REQUIRED"/>
        <tx:method name="edit*" propagation="REQUIRED"/>
        <tx:method name="del*" propagation="REQUIRED"/>
        <tx:method name="delete*" propagation="REQUIRED"/>
        <tx:method name="remove*" propagation="REQUIRED"/>
        <tx:method name="repair" propagation="REQUIRED"/>
        <tx:method name="persistence*" propagation="REQUIRED"/>

        <tx:method name="*" propagation="SUPPORTS" />
    </tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
    <aop:pointcut id="transactionPointcut" expression="execution(* com.test.service..*.*(..))" />
    <aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" />
</aop:config>

judge spring TX is active bug in SqlSessionUtils.getSqlSession of 1.2.2

In SqlSessionUtils.getSqlSession of version 1.2.2, the judge of spring TX is active
if (TransactionSynchronizationManager.isSynchronizationActive()) is wrong,
when I have register my own TransactionSynchronization, and do DB operation
in the afterCompletion method of my own TransactionSynchronization.

Transactions not working

I have an application set up with MyBatis and Spring, but instead of SqlTemplate DeafaultSqlSession is used. Also the UPDATE transaction does not update the DB although offline the SQL query works just fine. This is my configuration:

applicationContext.xml:

<bean id="userServiceImpl" class="com.service.UserServiceImpl">
  <property name="sqlSession" ref="sqlSession" />
</bean>

 <!-- enable transactions with annotations -->
<tx:annotation-driven/>

Transaction definition (spring-tx.xml):

<!-- Instruct Spring to perform declarative transaction management automatically on annotated classes. -->
 <tx:advice id="txAdvice" transaction-manager="transactionManager">
     <tx:attributes>
         <tx:method name="find*" read-only="true" propagation="REQUIRED" />
         <tx:method name="update*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
         <tx:method name="delete*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
         <tx:method name="save*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
         <tx:method name="*" read-only="false" propagation="REQUIRED" />
     </tx:attributes>
 </tx:advice>

 <!-- ensure that the above transactional advice runs for any execution of an operation defined by a service -->
 <aop:config>
     <aop:pointcut id="serviceOperation" expression="execution(* com.service.*Service.*(..))" />
     <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
 </aop:config>

 <aop:spring-configured />

 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
     <property name="dataSource" ref="dataSource" />
     <property name="validateExistingTransaction" value="true" />
 </bean>

myBatis-context.xml:

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="typeAliasesPackage" value="com.model"/> <!-- Register the short names of beans as aliases -->
    <property name="configLocation" value="classpath:mybatis-config.xml"/> //not shown for clarity
</bean>

<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
    <constructor-arg index="0" ref="sqlSessionFactory" />
</bean>

<!-- scan for mappers and let them be autowired -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.mapper" />
</bean>

Sample bean with transaction definition:
UserServiceImpl:

(...)

@Transactional(rollbackFor=RuntimeException.class)
public void update(User user) throws UserNotAvailableException, CloneNotSupportedException {...}

The log:

2013-06-17 15:39:37,757 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] <Creating new transaction with name [com.UserServiceImpl.findAll]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly>

2013-06-17 15:39:37,757 DEBUG [com.mchange.v2.resourcepool.BasicResourcePool] - <trace com.mchange.v2.resourcepool.BasicResourcePool@5fadce [managed: 1, unused: 0, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@df88d2)>
2013-06-17 15:39:37,757 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Acquired Connection [com.mchange.v2.c3p0.impl.NewProxyConnection@177daaa] for JDBC transaction>
2013-06-17 15:39:37,762 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - <Setting JDBC Connection [com.mchange.v2.c3p0.impl.NewProxyConnection@177daaa] read-only>
2013-06-17 15:39:37,763 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Switching JDBC Connection [com.mchange.v2.c3p0.impl.NewProxyConnection@177daaa] to manual commit>
17.06.2013 15:39:37.766 [SqlSessionUtils] [SqlSessionUtils.java] [DEBUG] [main ] Creating a new SqlSession
17.06.2013 15:39:37.769 [SqlSessionUtils] [SqlSessionUtils.java] [DEBUG] [main ] Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@954549]
17.06.2013 15:39:37.792 [SpringManagedTransaction] [SpringManagedTransaction.java] [DEBUG] [main ] JDBC Connection [com.mchange.v2.c3p0.impl.NewProxyConnection@177daaa] will be managed by Spring

... These two lines are shown instead when I try to perform a CRUD operation. Insert/Update does not modify the DB.

*18.06.2013 10:46:44.186 [SqlSessionUtils] [SqlSessionUtils.java] [DEBUG] [main ] Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1c8d5dd] from current transaction
18.06.2013 10:46:44.199 [SqlSessionUtils] [SqlSessionUtils.java] [DEBUG] [main ] Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1c8d5dd]
*

Is this is a bug in MyBatis or the fault is mine ? Any help will be appreciated.
Best wishes,
Lukasz

should mybatis spring add suport for batch commit for a couple of mappers working together ?

  mybatis spring provides us with batch configure with sqlsessiontemplate and also support for batch commit towards a single mapper while insert or update, but how about

a couple of mapper files commit, for sometimes in a transaction unit, it including a couple of mapper files each mapper would fetch a connection from the datasource, if
batch support is enable toward the mappers files,just like
AMapper. insert(***)

BMapper.update("")

CMapper.delete("")

A and B and C through mybatis could be subbmit to jdbc driver in a batch way, those will improve the performance and make the transaction around.

And I just know that sqlsession could be enable to fetch that, but it could not be
compatible with spring. so any one could help me solve such problem

Too many failures in scanning

I'm using Flyway (also experimenting with Liquibase) to manage database migration. So I have a setup like this:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" depends-on="flyway">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="classpath:mybatis-config.xml" />
    <property name="mapperLocations" value="classpath*:persistence/*.xml" />
    <property name="typeAliasesPackage" value="com.example.entity" />
    <property name="typeHandlersPackage" value="com.example.typehandler" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.example.persistence" />
</bean>

Now, when the migration fails, which is a failure to instantiate the flyway bean and consequently the sqlSessionFactory bean, I would expect to simply see an error message in the logs as to what went wrong.

What seems to happen instead is that the scanner attempts to recreate the bean over and over again. I see churning in the logs until eventually memory is exhausted. Or if I work around that, and wait very patiently, I see hundreds of duplicate errors spit out at the end.

I would guess this is all because of the business where the scanner needs a bean name rather than a ref.

So, is it possible to fix it so that it only attempts creating sqlSessionFactory once? Or is there a workaround I can do in my Spring config?

Too more entity mapper scan init out(maven-jetty-plugin start) error at 32-bit jdk,but 64-bit is good work.

Dear all:
Now find new problem jdk1.6.0 _45 64-bit start there is no problem, but 32-bit JDK start will report the same error

use maven jetty-plugin start log:

[INFO] Scanning for projects...

2014-01-14 12:36:55.328 ERROR [main] org.springframework.web.context.ContextLoader:324 >> Context initialization failed
java.lang.NoClassDefFoundError: Could not initialize class org.springframework.beans.factory.BeanCreationException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:532) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) ~[spring-context-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) ~[spring-context-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) ~[spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) ~[spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:771) [jetty-server-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424) [jetty-servlet-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:763) [jetty-server-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249) [jetty-servlet-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250) [jetty-webapp-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:706) [jetty-server-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492) [jetty-webapp-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:293) [jetty-maven-plugin-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) [jetty-util-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229) [jetty-server-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:172) [jetty-server-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) [jetty-util-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229) [jetty-server-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) [jetty-util-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95) [jetty-server-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.eclipse.jetty.server.Server.doStart(Server.java:277) [jetty-server-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:65) [jetty-maven-plugin-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) [jetty-util-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:511) [jetty-maven-plugin-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:364) [jetty-maven-plugin-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:523) [jetty-maven-plugin-8.1.8.v20121106.jar:8.1.8.v20121106]
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) [maven-core-3.0.5.jar:3.0.5]
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) [maven-core-3.0.5.jar:3.0.5]
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) [maven-core-3.0.5.jar:3.0.5]
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) [maven-core-3.0.5.jar:3.0.5]
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) [maven-core-3.0.5.jar:3.0.5]
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) [maven-core-3.0.5.jar:3.0.5]
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) [maven-core-3.0.5.jar:3.0.5]
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) [maven-core-3.0.5.jar:3.0.5]
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) [maven-core-3.0.5.jar:3.0.5]
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) [maven-core-3.0.5.jar:3.0.5]
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) [maven-embedder-3.0.5.jar:3.0.5]
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) [maven-embedder-3.0.5.jar:3.0.5]
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) [maven-embedder-3.0.5.jar:3.0.5]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_37]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_37]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_37]
at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_37]
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) [plexus-classworlds-2.4.jar:na]
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) [plexus-classworlds-2.4.jar:na]
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) [plexus-classworlds-2.4.jar:na]
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) [plexus-classworlds-2.4.jar:na]
2014-01-14 12:36:55.351:WARN:oejuc.AbstractLifeCycle:FAILED o.m.j.p.JettyWebAppContext{/bom,file:/E:/ymwork_6/bom/src/main/webapp/},file:/E:/ymwork_6/bom/src/main/webapp/: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.beans.factory.BeanCreationException
java.lang.NoClassDefFoundError: Could not initialize class org.springframework.beans.factory.BeanCreationException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:532)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:771)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:763)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:706)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)
at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:293)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:172)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
at org.eclipse.jetty.server.Server.doStart(Server.java:277)
at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:65)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:511)
at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:364)
at org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:523)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
2014-01-14 12:36:55.368:WARN:oejuc.AbstractLifeCycle:FAILED org.eclipse.jetty.server.handler.ContextHandlerCollection@11a070b: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.beans.factory.BeanCreationException
java.lang.NoClassDefFoundError: Could not initialize class org.springframework.beans.factory.BeanCreationException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:532)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:771)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:763)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:706)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)
at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:293)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:172)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
at org.eclipse.jetty.server.Server.doStart(Server.java:277)
at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:65)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:511)
at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:364)
at org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:523)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
2014-01-14 12:36:55.381:WARN:oejuc.AbstractLifeCycle:FAILED org.eclipse.jetty.server.handler.HandlerCollection@1c4a357: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.beans.factory.BeanCreationException
java.lang.NoClassDefFoundError: Could not initialize class org.springframework.beans.factory.BeanCreationException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:532)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:771)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:763)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:706)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)
at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:293)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:172)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
at org.eclipse.jetty.server.Server.doStart(Server.java:277)
at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:65)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:511)
at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:364)
at org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:523)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
2014-01-14 12:36:55.396:WARN:oejuc.AbstractLifeCycle:FAILED org.mortbay.jetty.plugin.JettyServer@55010f: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.beans.factory.BeanCreationException
java.lang.NoClassDefFoundError: Could not initialize class org.springframework.beans.factory.BeanCreationException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:532)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:771)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:763)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:706)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)
at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:293)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:172)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
at org.eclipse.jetty.server.Server.doStart(Server.java:277)
at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:65)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:511)
at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:364)
at org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:523)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
[INFO] Jetty server exiting.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 38.002s
[INFO] Finished at: Tue Jan 14 12:36:55 CST 2014
[INFO] Final Memory: 47M/495M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.mortbay.jetty:jetty-maven-plugin:8.1.8.v20121106:run (default-cli) on project bom: Execution default-cli of goal org.mortbay.jetty:jetty-maven-plugin:8.1.8.v20121106:run failed: A required class was missing while executing org.mortbay.jetty:jetty-maven-plugin:8.1.8.v20121106:run: Could not initialize class org.springframework.beans.factory.BeanCreationException

SqlSessionFactoryBean: set databaseId before xmlConfigBuilder.parse()

Issue for SqlSessionFactoryBean v1.2.2

I have a spring config:

  <bean id="standardSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="configLocation" value="classpath:mybatis.xml" />
    <property name="databaseIdProvider" ref="databaseIdProvider" />
    <property name="dataSource" ref="dataSource" />
  </bean>

The mybatis.xml contains all the mappers and in the mapper.xml there are dynamic sql:

  <sql id="reportDate" databaseId="h2">to_date(#{reportDate:VARCHAR}, 'YYYY-MM-DD')</sql>
  <sql id="reportDate" databaseId="oracle">#{reportDate:DATE}</sql>

  <select id="findForReport" resultMap="report">
    SELECT * FROM
...
           AND updated_dt >= <include refid="reportDate" />
           AND updated_dt &lt; <include refid="reportDate" /> + 1
  </select>

Currently setting the databaseId is done after xmlConfigBuilder.parse() in SeqlSessionFactoryBean#buildSqlSessionFactory() which means the query fails because it can't find the reportDate SQL statement. Setting the databaseId needs to be done before xmlConfigBuilder.parse().

Here is a patch for SqlSessionFactoryBean (v1.2.2):

425a426,433
>     if (this.databaseIdProvider != null) {
>       try {
>         configuration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource));
>       } catch (SQLException e) {
>         throw new NestedIOException("Failed getting a databaseId", e);
>       }
>     }
> 
446,453d453
< 
<     if (this.databaseIdProvider != null) {
<       try {
<         configuration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource));
<       } catch (SQLException e) {
<         throw new NestedIOException("Failed getting a databaseId", e);
<       }
<     }

MyBatisExceptionTranslator loose PersistenceException message

When MyBatis PersistenceException is translated to DataAccessException by MyBatisExceptionTranslator the original message from PersistenceException (ErrorContext message) gets lost. I've implemented my own ExceptionTranslator that preserves the original message - feel free to use it to update your MyBatisExceptionTranslator (my changes are marked with comments).

 public DataAccessException translateExceptionIfPossible(RuntimeException e) {
        // customized extension: store errorMessage from original exception 
        StringBuilder errorMessage = new StringBuilder(e.getMessage()).append("\n");
        if (e instanceof PersistenceException) {
          if (e.getCause() instanceof PersistenceException) {
            e = (PersistenceException) e.getCause();
            // customized extension: add error message from underlying exception
            errorMessage.append(e.getMessage()).append("\n");
          }
          if (e.getCause() instanceof SQLException) {
            this.initExceptionTranslator();
            // customized extension: pass errorMessage 
            return this.exceptionTranslator.translate(errorMessage.toString(), null, (SQLException) e.getCause());
          }
          return new MyBatisSystemException(e);
        } 
        return null;
      }

multiple datasource spring config user properties conf exception

spring conf

<context:property-placeholder location="classpath:conf.properties" />
<tx:annotation-driven transaction-manager="transactionManager_citsmdb"
    proxy-target-class="true" />
<tx:annotation-driven transaction-manager="transactionManager_xmondb"
    proxy-target-class="true" />
<bean id="dataSource_citsmdb" class="com.alibaba.druid.pool.DruidDataSource">
    <property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver" />
    <property name="url"
        value="jdbc:jtds:sqlserver://rdtoolssql:15668;DatabaseName=citsmdb" />
    <property name="username" value="rduser" />
    <property name="password">
        <bean class="rdtools.xmon.util.EncryptDBPasswordFactory">
            <property name="password" value="xxxxxxx" />
        </bean>
    </property>
    <property name="initialSize" value="${citsmdb.jdbc.initialSize}" />
    <property name="maxActive" value="50" />
    <property name="maxIdle" value="20" />
    <property name="minIdle" value="0" />
    <property name="maxWait" value="60000" />
</bean>
<bean id="transactionManager_citsmdb"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource_citsmdb" />
</bean>
<bean id="sqlSessionFactory_citsmdb" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource_citsmdb" />
    <property name="typeAliasesPackage" value="rdtools.xmon.pojo.citsmdb" />
</bean>
<bean name="mybatis_citsmdb" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="rdtools.xmon.persist.citsmdb" />
    <property name="sqlSessionFactory" ref="sqlSessionFactory_citsmdb" />
</bean>
<bean id="dataSource_xmondb" class="com.alibaba.druid.pool.DruidDataSource"
    init-method="init" destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://192.168.0.770:3306/hitest" />
    <property name="username" value="rduser" />
    <property name="password">
        <bean class="rdtools.xmon.util.EncryptDBPasswordFactory">
            <property name="password" value="xxxxx" />
        </bean>
    </property>
    <property name="initialSize" value="${xmondb.jdbc.initialSize}" />
    <property name="maxActive" value="50" />
    <property name="maxIdle" value="20" />
    <property name="minIdle" value="0" />
    <property name="maxWait" value="60000" />
</bean>

start server exception

org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'initialSize'; nested exception is java.lang.NumberFormatException: For input string: "${xmondb.jdbc.initialSize}"
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:468)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:494)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:488)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1433)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1392)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:323)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1387)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:323)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1387)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:439)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:624)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at rdtools.xmon.listener.ServerContextLoaderListener.contextInitialized(ServerContextLoaderListener.java:18)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:775)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:767)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1252)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:710)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494)
at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:293)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:172)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
at org.eclipse.jetty.server.Server.doStart(Server.java:282)
at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:65)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:520)
at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:365)
at org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:523)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by:
java.lang.NumberFormatException: For input string: "${xmondb.jdbc.initialSize}"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:449)
at java.lang.Integer.valueOf(Integer.java:554)
at org.springframework.util.NumberUtils.parseNumber(NumberUtils.java:155)
at org.springframework.beans.propertyeditors.CustomNumberEditor.setAsText(CustomNumberEditor.java:115)
at org.springframework.beans.TypeConverterDelegate.doConvertTextValue(TypeConverterDelegate.java:452)
at org.springframework.beans.TypeConverterDelegate.doConvertValue(TypeConverterDelegate.java:424)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:181)
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:448)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:494)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:488)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1433)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1392)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:323)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1387)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:323)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1387)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:439)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:624)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at rdtools.xmon.listener.ServerContextLoaderListener.contextInitialized(ServerContextLoaderListener.java:18)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:775)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:767)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1252)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:710)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494)
at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:293)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:172)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
at org.eclipse.jetty.server.Server.doStart(Server.java:282)
at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:65)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:520)
at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:365)
at org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:523)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)

btw:
${citsmdb.jdbc.initialSize} in conf.properties

SQLSession not being released after transaction commit

I am using Spring transactions (JTA), but programatically not declaratively. Everything is working correctly in as much as the database commits are made correctly, however the sqlsession is not being released back into the pool and so eventually I run out of connections.

In the logs around the mybatis calls I can see, the session being obtained:-

DEBUG [org.mybatis.spring.SqlSessionUtils] [http-/127.0.0.1:8082-1] [getSqlSession] [userId=] Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@85e4f09] from current transaction

and apparently released:-

DEBUG [org.mybatis.spring.SqlSessionUtils] [http-/127.0.0.1:8082-1] [closeSqlSession] [userId=] Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@85e4f09]

But after the commit on the transaction manager, the TransactionSynchronizationManager shows the following resources are still bound:-
Key=org.jboss.jca.adapters.jdbc.WrapperDataSource@783bd98c
Value=org.springframework.jdbc.datasource.ConnectionHolder

Key=org.apache.ibatis.session.defaults.DefaultSqlSessionFactory@126b9996
Value=org.mybatis.spring.SqlSessionHolder

I am running on JBoss 6.3, Oracle 11g and the latest version of mybatis spring.

I am wondering whether this is related to the issue from Bug 18 (#18)?

sqlSessionFactory is needed when using mybatis:scan

per the document at: http://mybatis.github.io/spring/mappers.html#scan

"Notice that there is no need to specify a SqlSessionFactory or SqlSessionTemplate because the mybatis:scan/ will create MapperFactoryBeans that can be autowired."

however, I ran into the following exception:

"Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required"

After adding one bean definition of org.mybatis.spring.SqlSessionFactoryBean, the problem is solved.

Is the document wrong? or it only works for certain version?

I am using following version of mybatis and mybatis-spring:

org.mybatis mybatis 3.2.0 org.mybatis mybatis-spring 1.2.0

any idea?

autoMapping part in manual

http://mybatis.github.io/mybatis-3/ko/sqlmap-xml.html#Auto-mapping
http://mybatis.github.io/mybatis-3/sqlmap-xml.html#Auto-mapping

In manual, we can use autoMapping on select and resultMap

resultMap is working but

<select id="selectUsers" resultType="User"  autoMapping="false">
  select
    user_id             as "id",
    user_name           as "userName",
    hashed_password
  from some_table
  where id = #{id}
</select>

select occurs xml validation error

https://github.com/mybatis/mybatis-3/blob/master/src/main/java/org/apache/ibatis/builder/xml/mybatis-3-mapper.dtd

In mybatis3-mapper.dtd, there is no autoMapping property on select

Could I edit this manual and pull request?

ClasspathMapperScanner does not use constructor

relates to #58

ClasspathMapperScanner still uses property injection for mapper interface instead of (new) constructor:

definition.getPropertyValues().add("mapperInterface", definition.getBeanClassName());

should be

definition.getConstructorArgumentValues().addGenericArgumentValue(definition.getBeanClassName());

therefore mit mybatis-spring-1.2.3 i still get the error-message

"...Bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCreationException ..."

i verified that it works when using constructor injection.

spring ignoring bean creation exception on FactoryBean type check

Hi,all
mybatis3.2.7, mybatis-spring1.2.2, spring4.1.1 , when the mapper file is error, such as , the "DATETIME" is not allow by mybatis,but the spring was not throw the exception ,tho only script is
/*
if (logger.isDebugEnabled()) {
logger.debug("Ignoring bean creation exception on FactoryBean type check: " + ex);
}
*/
so the mybatis was in loop, loop,loop ,the spring was in initializeBean,initializeBean,initializeBean.

I don't know if you understand my mind.

I was anxiously for this.

MyBatis-Spring should not use any DatabaseIdProvider by default

MyBatis does not use any DatabaseIdProvider by default but the Spring integration module does. This is not consistent.

Moreover, using the VendorDatabaseIdProvider with no further configuration is probably useless.

We also need some more documentation about how to configure this feature when using Spring. At least some sample XML in the manual.

SqlSessionFactoryBean falls in circular dependencies by Spring Boot's DataSourceInitializer.

SqlSessionFactoryBean falls in circular dependencies by Spring Boot's DataSourceInitializer.

With @Lazy annotations it's okay but without them the following exception occurs:

Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sqlSessionFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?

A project with @Lazy annotations:
https://github.com/izeye/samples-spring-boot-branches/tree/mybatis-hsqldb

A project without @Lazy annotations:
https://github.com/izeye/samples-spring-boot-branches/tree/mybatis-hsqldb-without-lazy

I guess replacing ApplicationListener<ApplicationEvent> with ApplicationListener<ContextRefreshedEvent> would fix it.

If my usage is incorrect, please let me know.

mybatis-spring OSGi imports - Spring batch should be optional

The old issue is still actual for _mybatis-spring 1.2.0_

Here is the log

JBossFuse:admin@root> start 127
Error executing command: Error starting bundles:
        Unable to start bundle 127: Unresolved constraint in bundle org.mybatis.mybatis-spring [127]: Unable to resolve 127.0: missing requirement [127.0] osgi.wiring.package; (osgi.wiring.package=org.springframework.batch.item)
JBossFuse:admin@root> headers 127

MyBatis-Spring (127)
--------------------
Specification-Title = MyBatis-Spring
Archiver-Version = Plexus Archiver
Tool = Bnd-1.50.0
Specification-Version = 1.2.0
Specification-Vendor = MyBatis.org
Implementation-Version = 1.2.0
Build-Jdk = 1.6.0_37
Implementation-Build-Date = 2013-02-20 20:58:18+0100
Implementation-Vendor-Id = org.mybatis
Created-By = Apache Maven Bundle Plugin
Implementation-Title = MyBatis-Spring
Manifest-Version = 1.0
Bnd-LastModified = 1361390302535
X-Compile-Target-JDK = 1.5
Include-Resource = META-INF/LICENSE=LICENSE,META-INF/NOTICE=NOTICE,META-INF/spring.handlers=src/main/java/META-INF/spring.handlers,META-INF/spring.schemas=src/main/java/META-INF/spring.schemas,org/mybatis/spring/config/mybatis-spring-1.2.xsd=src/main/java/org/mybatis/spring/config/mybatis-spring-1.2.xsd
Built-By = stripodi
X-Compile-Source-JDK = 1.5
Implementation-Vendor = MyBatis.org

Bundle-Vendor = MyBatis.org
Bundle-Name = MyBatis-Spring
Bundle-DocURL = http://www.mybatis.org/spring/
Bundle-Description = An easy-to-use Spring3 bridge for MyBatis sql mapping framework.
Bundle-SymbolicName = org.mybatis.mybatis-spring
Bundle-Version = 1.2.0
Bundle-License = http://www.apache.org/licenses/LICENSE-2.0.txt
Bundle-ManifestVersion = 2

DynamicImport-Package =
        *
Import-Package =
        javax.sql,
        org.apache.commons.logging,
        org.apache.ibatis.builder.xml,
        org.apache.ibatis.exceptions,
        org.apache.ibatis.executor,
        org.apache.ibatis.logging,
        org.apache.ibatis.mapping,
        org.apache.ibatis.plugin,
        org.apache.ibatis.reflection,
        org.apache.ibatis.reflection.factory,
        org.apache.ibatis.reflection.wrapper,
        org.apache.ibatis.session,
        org.apache.ibatis.transaction,
        org.apache.ibatis.type,
        org.springframework.batch;resolution:=optional,
        org.springframework.batch.item,
        org.springframework.batch.item.database,
        org.springframework.beans,
        org.springframework.beans.factory,
        org.springframework.beans.factory.annotation,
        org.springframework.beans.factory.config,
        org.springframework.beans.factory.support,
        org.springframework.beans.factory.xml,
        org.springframework.context,
        org.springframework.context.annotation,
        org.springframework.context.event,
        org.springframework.context.support,
        org.springframework.core,
        org.springframework.core.annotation,
        org.springframework.core.io,
        org.springframework.core.type,
        org.springframework.core.type.classreading,
        org.springframework.core.type.filter,
        org.springframework.dao,
        org.springframework.dao.support,
        org.springframework.jdbc.datasource,
        org.springframework.jdbc.support,
        org.springframework.transaction.support,
        org.springframework.util,
        org.w3c.dom
Export-Package =
        org.mybatis.spring.annotation;version=1.2.0,
        org.mybatis.spring.mapper;version=1.2.0,
        org.mybatis.spring.batch;version=1.2.0,
        org.mybatis.spring.transaction;version=1.2.0,
        org.mybatis.spring.config;version=1.2.0,
        org.mybatis.spring;version=1.2.0,
        org.mybatis.spring.support;version=1.2.0

As you can see

    org.springframework.batch;resolution:=optional,
    org.springframework.batch.item,
    org.springframework.batch.item.database,

only org.springframework.batch has optional resolution.

The pom.xml should be changed like the following

<osgi.import>org.springframework.batch*;resolution:=optional,*</osgi.import> 

Pay attention to additional * after the package name.

SqlSessionUtils code is not up to date

I'm using maven to download the latest 1.2.2 version of the code (from the Central Repo). The code I see for SqlSessionUtils does not match what is up on GitHub, namely the afterCompletion method:

    public void afterCompletion(int status) {
      if (this.holderActive) {
        // afterCompletion may have been called from a different thread
        // so avoid failing if there is nothing in this one
        if (logger.isDebugEnabled()) {
          logger.debug("Transaction synchronization deregistering SqlSession [" + this.holder.getSqlSession() + "]");
        }
        TransactionSynchronizationManager.unbindResourceIfPossible(sessionFactory);
        this.holderActive = false;
        if (logger.isDebugEnabled()) {
          logger.debug("Transaction synchronization closing SqlSession [" + this.holder.getSqlSession() + "]");
        }
        this.holder.getSqlSession().close();
      }
      this.holder.reset();
    }
  }

As you can see, the transaction handling is missing, which is causing a problem w/my unit tests. I checked the sha of the file to make sure I got what is currently up in the repo and it is. I think the wrong version of the class got packaged and pushed out to Maven repos.

check cache after get connection when too many client request the same data record

Analyze:

check cache is done before get connection,and get connection is a blocked operation。since check cache very fast than SpringManagedTransaction.openConnection,If the datasource or database only support 30 connections, and 1000 clients request the same data record and call DefaultSqlSession.selectList, all clients request will not get data from cache.

Suggest:check cache after get connection or other clients should be blocked until completion of the first client queries when they request the same data record.

Call stack

com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:97)
org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:81)
org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67)
org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:271)
org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:69)
org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:56)
org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:259)
org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:132)
org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:100)
org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81)
sun.reflect.GeneratedMethodAccessor16.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:46)
cn.org.rapid_framework.mybatis.plugin.OffsetLimitInterceptor.intercept(OffsetLimitInterceptor.java:63)
org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:57)
$Proxy38.query(Unknown Source)
org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)
org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98)
org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:94)

check cache
org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:100)

block
org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:81)

org.mybatis.spring.transaction.SpringManagedTransaction.logger should be static

I have a hotspot in my application for opening a new transaction. It turns out that the slowdown is in LogFactory.getLog(), which creates a new instance of the delegated constructor every time it is called. This isn't a big deal for most users of LogFactory, but SpringManagedTransaction creates a new log instance for every transaction, and there is no reason why it should.
bug-mybatis-spring

Too more entity mapper scan init out error

Dear:

use version:
mybatis-spring: 1.1.1
spring:3.2.1.RELEASE
mybatis:3.1.1

The spring config file :

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

        <property name="dataSource" ref="dataSource" />
        <property name="typeAliasesPackage" value="com.allinpay" />
        <property name="mapperLocations" value="classpath*:mybatis/**/*Mapper.xml" />
        <property name="plugins">
            <array>
                <ref bean="paginationInterceptor" />
            </array>
        </property>
        <property name="configurationProperties">
            <props>
                <prop key="dialect">oracle</prop>
            </props>
        </property>
    </bean>

    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg index="0" ref="sqlSessionFactory" />
    </bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.allinpay" />
        <property name="annotationClass" value="com.allinpay.its.boss.framework.repository.mybatis.MyBatisRepository" />
    </bean>

MyBatisRepository code:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface MyBatisRepository {
}

now my question is end:

If the scan entity is not a lot,the jetty start work good,no problem!

But, If the scan entity of more than 150 ,jetty start out err:

java.lang.NoClassDefFoundError: Could not initialize class org.springframework.beans.factory.BeanCreationException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:532) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) ~[spring-context-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) ~[spring-context-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) ~[spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) ~[spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:771) [jetty-server-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424) [jetty-servlet-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:763) [jetty-server-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249) [jetty-servlet-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250) [jetty-webapp-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:706) [jetty-server-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492) [jetty-webapp-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:293) [jetty-maven-plugin-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) [jetty-util-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229) [jetty-server-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:172) [jetty-server-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) [jetty-util-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229) [jetty-server-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) [jetty-util-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95) [jetty-server-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.eclipse.jetty.server.Server.doStart(Server.java:277) [jetty-server-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:65) [jetty-maven-plugin-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) [jetty-util-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:511) [jetty-maven-plugin-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:364) [jetty-maven-plugin-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:523) [jetty-maven-plugin-8.1.8.v20121106.jar:8.1.8.v20121106]
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) [maven-core-3.0.5.jar:3.0.5]
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) [maven-core-3.0.5.jar:3.0.5]
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) [maven-core-3.0.5.jar:3.0.5]
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) [maven-core-3.0.5.jar:3.0.5]
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) [maven-core-3.0.5.jar:3.0.5]
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) [maven-core-3.0.5.jar:3.0.5]
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) [maven-core-3.0.5.jar:3.0.5]
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) [maven-core-3.0.5.jar:3.0.5]
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) [maven-core-3.0.5.jar:3.0.5]
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) [maven-core-3.0.5.jar:3.0.5]
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) [maven-embedder-3.0.5.jar:3.0.5]
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) [maven-embedder-3.0.5.jar:3.0.5]
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) [maven-embedder-3.0.5.jar:3.0.5]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_37]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_37]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_37]
    at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_37]
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) [plexus-classworlds-2.4.jar:na]
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) [plexus-classworlds-2.4.jar:na]
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) [plexus-classworlds-2.4.jar:na]
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) [plexus-classworlds-2.4.jar:na]

Now the problem is especially urgent,Please !!!

message error may confused

first,i write daoMapper like this

    @Update("Update t_order_status_cal SET is_handled = 1, handled_time = #{ht} WHERE order_id = #{}")
    public int updateHandledTime(@Param("orderId") long orderId, @Param("ht") Timestamp handledTime);

but there is an mistake, i miss the orderId param in sql

so when i start the web container and invoke this method updateHandledTime
mybatis throw this exception
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

i don't think this is an good message for user to understand,
i think the good way to explain this error may be sql parse error

@MapperScan not working with SqlSessionFactory Beans using Injected DataSources

I have the following @configuration class:

@Configuration
@MapperScan("my.packages")
public class MyBatisConfiguration {

    @Inject
    IDatabaseConfiguration databaseConfiguration;

    @Inject
    Environment environment;

    /*
     * Producer der Data-Access-Objects
     */

    @Bean
    @Singleton
    public SqlSessionFactory sqlSessionFactory() throws Exception {
        final SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(this.databaseConfiguration.dataSource());
        final SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBean.getObject();
        return sqlSessionFactory;
    }

/* other stuff follows */

}

On Deploying my Software I'm getting:

Caused by: java.lang.NullPointerException
    at my.packages.configs.MyBatisConfiguration.sqlSessionFactory(MyBatisConfiguration.java:43) [my-software.jar:]
    at my.packages.configs.MyBatisConfiguration$$EnhancerByCGLIB$$9fa90036.CGLIB$sqlSessionFactory$0(<generated>) [spring-core-3.2.3.RELEASE.jar:]
    at my.packages.configs.MyBatisConfiguration$$EnhancerByCGLIB$$9fa90036$$FastClassByCGLIB$$297e35da.invoke(<generated>) [spring-core-3.2.3.RELEASE.jar:]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) [spring-core-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:286) [spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at my.packages.configs.MyBatisConfiguration$$EnhancerByCGLIB$$9fa90036.sqlSessionFactory(<generated>) [spring-core-3.2.3.RELEASE.jar:]
    at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source) [:1.6.0_38]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_38]
    at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_38]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:160) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    ... 59 more

Using a Statically defined Datasource seems to work, but this is not an option for us.

Please fix this, or advise how to work around. Thank you!

MyBatisBatchItemWriter supports converting a parameter

Could MyBatisBatchItemWriter supports additional parameter that is not part of the item to be written?

e.g. My target db table contains the "last updated by" field which is not part of the domain object (The object doesn't have the lastUpdatedBy property). In typical MyBatis usage, I could use @param to pass additional parameter. It would be nice if MyBatisBatchItemWriter could provide some alternatives like this.

Problem with transaction

I encounter an failure while evaluating mybatis-spring 1.2.0 with mybatis 3.2.2 and Spring 3.2.2. The declarative transaction didn't work while the programatic transaction went well.

I try to insert two record into mysql innodb table with one record contain a wrong value on a column with unique index constraint. while using programatic transaction, it rollback all the operation normally. then I shift to declarative transaction, it dosen't work. I dig into the log and find something abnormal. Here is the segment of log.

2013-05-15 16:56:57 378 DEBUG: com.ssports.db.TransTest - Invoking service method[addRecords]
2013-05-15 16:56:57 381 DEBUG: org.springframework.jdbc.datasource.DataSourceTransactionManager - Creating new transaction with name [com.ssports.test.service.TestServiceImpl.addRecords]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2013-05-15 16:56:57 382 DEBUG: org.springframework.jdbc.datasource.DataSourceTransactionManager - Acquired Connection [org.apache.commons.dbcp.PoolableConnection@534393e8] for JDBC transaction
2013-05-15 16:56:57 384 DEBUG: org.springframework.jdbc.datasource.DataSourceTransactionManager - Switching JDBC Connection [org.apache.commons.dbcp.PoolableConnection@534393e8] to manual commit
2013-05-15 16:56:57 385 INFO : com.ssports.test.service.TestServiceImpl - 4:1368608217
2013-05-15 16:56:57 385 DEBUG: org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession
2013-05-15 16:56:57 386 DEBUG: org.mybatis.spring.SqlSessionUtils - Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@246bee46]
2013-05-15 16:56:57 389 DEBUG: org.mybatis.spring.transaction.SpringManagedTransaction - JDBC Connection [org.apache.commons.dbcp.PoolableConnection@3c9053ac] will be managed by Spring
2013-05-15 16:56:57 389 DEBUG: com.ssports.test.mapper.RecordMapper.insert - ooo Using Connection [org.apache.commons.dbcp.PoolableConnection@3c9053ac]
2013-05-15 16:56:57 389 DEBUG: com.ssports.test.mapper.RecordMapper.insert - ==> Preparing: insert into test (id, content, position, time) values (?, ?, ?, ?)
2013-05-15 16:56:57 390 DEBUG: com.ssports.test.mapper.RecordMapper.insert - ==> Parameters: null, ddd(String), 4(Integer), 1368608217(Integer)
2013-05-15 16:56:57 436 DEBUG: org.mybatis.spring.SqlSessionUtils - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@246bee46]
2013-05-15 16:56:57 436 INFO : com.ssports.test.service.TestServiceImpl - 0:1368164281
2013-05-15 16:56:57 436 DEBUG: org.mybatis.spring.SqlSessionUtils - Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@246bee46] from current transaction
2013-05-15 16:56:57 437 DEBUG: com.ssports.test.mapper.RecordMapper.insert - ooo Using Connection [org.apache.commons.dbcp.PoolableConnection@3c9053ac]
2013-05-15 16:56:57 437 DEBUG: com.ssports.test.mapper.RecordMapper.insert - ==> Preparing: insert into test (id, content, position, time) values (?, ?, ?, ?)
2013-05-15 16:56:57 437 DEBUG: com.ssports.test.mapper.RecordMapper.insert - ==> Parameters: null, test(String), 0(Integer), 1368164281(Integer)
2013-05-15 16:56:57 514 DEBUG: org.mybatis.spring.SqlSessionUtils - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@246bee46]
2013-05-15 16:56:57 514 DEBUG: org.springframework.jdbc.datasource.DataSourceTransactionManager - Initiating transaction rollback
2013-05-15 16:56:57 514 DEBUG: org.springframework.jdbc.datasource.DataSourceTransactionManager - Rolling back JDBC transaction on Connection [org.apache.commons.dbcp.PoolableConnection@534393e8]
2013-05-15 16:56:57 515 DEBUG: org.mybatis.spring.SqlSessionUtils - Transaction synchronization rolling back SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@246bee46]
2013-05-15 16:56:57 515 DEBUG: org.mybatis.spring.SqlSessionUtils - Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@246bee46]
2013-05-15 16:56:57 516 DEBUG: org.springframework.jdbc.datasource.DataSourceTransactionManager - Releasing JDBC Connection [org.apache.commons.dbcp.PoolableConnection@534393e8] after transaction
2013-05-15 16:56:57 516 DEBUG: com.ssports.db.TransTest - Exception throw
2013-05-15 16:56:57 516 DEBUG: com.ssports.db.TransTest -

Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '0' for key 'position'

The connection object used by Spring Transaction Manager is different with the one applied in the sql operation. one is 'org.apache.commons.dbcp.PoolableConnection@534393e8' and the other is 'org.apache.commons.dbcp.PoolableConnection@3c9053ac'.

I'm not sure whether it's a bug or I did configuration wrong, please help. Thanks.

SqlSessionTemplate.getConnection is dead-on-arrival.

I need to integrate with some legacy JDBC code.

I am using mybatis 3.2.1 and mybatis-spring 1.2.0.

As an integration point I am using SqlSessionDaoSupport.

What I am trying to do is this:

SqlSession session = getSqlSession( );

Connection con = session.getConnection( );

try
{
  callLegacyCode( con );
}
finally
{
  con.close( );
}

However, inside SqlSessionTemplate, the call get proxied to SqlSessionInterceptor inner class, and there it's wrapped as such

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
  final SqlSession sqlSession = getSqlSession(...);
  try {
    Object result = method.invoke(sqlSession, args);
        ...
    return result;
  } finally {
    closeSqlSession(sqlSession, SqlSessionTemplate.this.sqlSessionFactory);
 }
}

As you can see after it's getting connection in method.invoke, it's immediately killed in the finally block, because the session that is holding it is closed.

A wrongly translated sentence in Korean

I really don't know where to issue. Sorry if I'm in a wrong place.

For following original sentence,

With MyBatis-Spring you don't need to use SqlSessionFactory directly because your beans can be injected with a thread safe SqlSession that automatically commits, rollbacks and closes the session based on Spring's transaction configuration.

There are three Korean sentences translated.

마이바티스 스프링 연동모듈을 사용하면 SqlSessionFactory를 직접 사용할 필요가 없다.
왜냐하면 사용할 빈이 SqlSession에 주입될수 있기 때문이다.
이때 SqlSession은 스프링 트랜잭션 설정에 따라 세션을 자동으로 커밋, 롤백하고 닫는 쓰레드에 안전하다.

The second sentence is completely wrong. It's saying those beans are injected into SqlSessions which implies the opposite direction.

Here is my suggestion. (I'm not sure of merging the 2nd and 3rd sentence, though.)

왜냐하면, 스프링 트랜잭션 설정에 따라 자동으로 커밋 혹은 롤백을 수행하고 닫혀지는, 쓰레드에 안전한 SqlSession개체가 스프링 빈에 주입될 수 있기 때문이다.

ThreadLocal cleanup fails when afterCompletion is called on a new Thread

There is no guarantee that TransactionSynchronization.afterCompletion is called in the same thread as the transaction itself. For example when using WebLogic JTA this happens quite a bit.

This prevents unbindResource in org.mybatis.spring.SqlSessionUtils.SqlSessionSynchronization.afterCompletion from completing successfully. This causes problems downstream - sessions not being closed and connection not disposed of.

The solution I see is moving unbindResource to beforeCompletion. Not sure about the rest of the code in afterCompletion as it relies on txn commit outcome.

Any comments before I submit a test case and patch?

Background on how the problem was found:
http://blog.ryaltech.com/2013/11/18/connection-closed-mybatis-spring/

org.mybatis.spring.SqlSessionFactoryBean is an ApplicationListener which effectively disables lazy-init

in some cases my users don't want to use a DB (i.e. use a mock). The fact that SqlSessionFactoryBean is an ApplicationListener results in my library to always try and connect to the DB even when it shouldn't. Usually this can be avoided using lazy-init.

This is the way I use it:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" lazy-init="true">
    <property name="dataSource" ref="dataSource" />
    <property name="mapperLocations" ref="mapperLocations" />
    <property name="transactionFactory" ref="jdbcTransactionFactory" />
</bean>

Assume that the bean "dataSource" is not my bean hence I can't mock it.

Use SqlSessionTemplate can't get mysql automatic increase PK, The PK is null

I use spring4.0.6+mybatis-spring1.2.2+mybatis3.2.7+mysql5

spring4 configuration file:

<context:component-scan base-package="com.shengyuan.syep">
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
    init-method="init" destroy-method="close">
      <property name="driverClassName" value="${jdbc.driverClassName}" />  

      <property name="url" value="${jdbc.url}" />
      <property name="username" value="${jdbc.username}" />
      <property name="password" value="${jdbc.password}" />

</bean>

<!-- mybatis3 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="classpath:mybatis/mybatis-config.xml" />
</bean>

<!-- mybatis3 spring3 template -->
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate" scope="prototype">
    <constructor-arg index="0" ref="sqlSessionFactory" />
    <constructor-arg index="1" value="BATCH" />
</bean>

mybatis configuration file:

<mappers>
    <mapper resource="com/shengyuan/syep/sys/user/model/UserMapper.xml"/>
</mappers>

the User model class:
package com.shengyuan.syep.sys.user.model;

public class User implements java.io.Serializable{

private static final long serialVersionUID = -1391499260552885715L;

private Long id;
private String userCode;
private String userName;


public Long getId() {
    return id;
}
public void setId(Long id) {
    this.id = id;
}
public String getUserCode() {
    return userCode;
}
public void setUserCode(String userCode) {
    this.userCode = userCode;
}
public String getUserName() {
    return userName;
}
public void setUserName(String userName) {
    this.userName = userName;
}

}

mapper configuration file:

<resultMap type="User" id="UserMap">
    <id column="id" property="id" javaType="java.lang.Long" jdbcType="INTEGER" />
    <id column="userCode" property="userCode" javaType="java.lang.String" jdbcType="VARCHAR" />
    <id column="userName" property="userName" javaType="java.lang.String" jdbcType="VARCHAR" />
</resultMap>


<insert id="saveUser" parameterType="User" useGeneratedKeys="true" keyProperty="id" keyColumn="id" >
     <![CDATA[
    INSERT INTO sys_user(userCode,userName) VALUES (#{userCode},#{userName})
    ]]> 
</insert> 

UserDao interface:
package com.shengyuan.syep.sys.user.dao;

import com.shengyuan.syep.sys.user.model.User;

public interface UserDao {
public int save(User user);
}

UserDaoImpl class:
package com.shengyuan.syep.sys.user.dao.impl;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import com.shengyuan.syep.sys.user.dao.UserDao;
import com.shengyuan.syep.sys.user.model.User;

@repository("userDao")
public class UserDaoImpl implements UserDao {
@resource
private SqlSessionTemplate sqlSessionTemplate;

@Override
public int save(User user) {
    return sqlSessionTemplate.insert("com.shengyuan.syep.sys.user.model.User.saveUser",user);
}

}

junit Test:
package com.shengyuan.syep.sys.user.dao;

import javax.annotation.Resource;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.shengyuan.syep.AbstractBaseSpringTest;
import com.shengyuan.syep.sys.user.model.User;

public class UserDaoTest extends AbstractBaseSpringTest {

private static final String USER_CODE = "long";
private static final String USER_NAME = "黄成";


@Resource
private UserDao userDao;

private User user =  null;

@Before
public void init(){
    user = new User();
    user.setUserCode(USER_CODE);
    user.setUserName(USER_NAME);
}

@Test
public void testSave() {
    int i = userDao.save(user);
    System.out.println(user.getId());
    not("", i,0);
    not("", i,1);
}


@After
public void destory(){
    user = null;
}

}
log:
2014-08-30 16:39:53.396 [main] DEBUG org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession
2014-08-30 16:39:53.423 [main] DEBUG org.mybatis.spring.SqlSessionUtils - Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3a2dbd76]
2014-08-30 16:39:53.439 [main] DEBUG org.mybatis.spring.transaction.SpringManagedTransaction - JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@652371d] will be managed by Spring
2014-08-30 16:39:53.483 [main] DEBUG com.shengyuan.syep.sys.user.model.User.saveUser - ==> Preparing: INSERT INTO sys_user(userCode,userName) VALUES (?,?)
2014-08-30 16:39:53.686 [main] DEBUG com.shengyuan.syep.sys.user.model.User.saveUser - ==> Parameters: long(String), 黄成(String)
2014-08-30 16:39:53.688 [main] DEBUG org.mybatis.spring.SqlSessionUtils - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3a2dbd76]
null
2014-08-30 16:39:58.734 [main] DEBUG org.mybatis.spring.SqlSessionUtils - Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3a2dbd76]
2014-08-30 16:39:58.748 [main] DEBUG org.mybatis.spring.SqlSessionUtils - Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3a2dbd76]
2014-08-30 16:39:58.749 [main] DEBUG org.mybatis.spring.SqlSessionUtils - Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3a2dbd76]

The PK is null

Output a warning log when 'mapperLocations' was specified but matching resources are not found

I found out someting interesting. mapperLocations property in my xml configuration file points to non-existing path:

 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="typeAliasesPackage" value="com.ucware.ucpo.statemachine.model"/> <!-- Register the short names of beans as aliases -->
    <property name="configLocation" value="classpath:mybatis-config.xml"/>
    <property name="mapperLocations" value="classpath*:/com/state/persistence/mapper/*.xml" />
</bean>

Still org.mybatis.spring.SqlSessionFactoryBean reports no exception.
this.mapperLocations is empty and execution continues.

In my case the correct link to the mapper is:
classpath_:/com/missing_entry/state/persistence/mapper/_.xml

Should not the exception be thrown ?

I use mybatis-spring.1.2.0.

SqlSessionFactoryBean needs to initialize databaseId from databaseIdProver before parsing XML Config

I am taking advantage of an embedded Derby database for build-time integration tests whilst my production software runs on MySQL.

In my XML I am making use of MyBatis's databaseIdProvider feature so that I can have specific to each database type.

<selectKey databaseId="derby" keyProperty="feedId" order="AFTER" resultType="java.lang.Long">
  VALUES IDENTITY_VAL_LOCAL()
</selectKey>
<selectKey  databaseId="mysql" keyProperty="feedId" order="AFTER" resultType="java.lang.Long">
  SELECT LAST_INSERT_ID()
</selectKey>

The trouble is, SqlSessionFactoryBean, despite having its own databaseIdProvider calls configuration.setDatabaseId() too late, after parsing the XML configuration, meaning that all my database specific selectKeys get thrown away.

If I use a modified version that sequences the setDatabaseId call earlier, all works fine.

org.mybatis.spring.SqlSessionFactoryBean is an ApplicationListener which effectively disables lazy-init

In some cases my users don't want to use a DB (i.e. use a mock). The fact that SqlSessionFactoryBean is an ApplicationListener results in my library to always try and connect to the DB even when it shouldn't. Usually this can be avoided using lazy-init.

This is the way I use it:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" lazy-init="true">
    <property name="dataSource" ref="dataSource" />
    <property name="mapperLocations" ref="mapperLocations" />
    <property name="transactionFactory" ref="jdbcTransactionFactory" />
</bean>

Assume that the bean "dataSource" is not my bean hence I can't mock it. Also I am not using DatabaseIdProvider directly.

Deadlock in MyBatisExceptionTranslator

It is possible to trigger a deadlock in the MyBatisExceptionTranslator : this class lazily-inits an SQLExceptionTranslator object, and this requires a connection from the current DataSource. If this DataSource has an empty connection-pool (maxActive reached) and the threads currently holding connections from the pool also trigger SQL exceptions then deadlock occurs.

This is with mybatis-spring 1.1.1 (mybatis 3.2.2). I haven't tried to reproduce on the latest release, but have looked at the latest source-code and can't see any related changes in the code that causes this problem.

I can reliably reproduce this with a test case:

  • datasource wraps a connection-pool with maxActive=5
  • a set of 10 threads simultaneously use an SqlSessionTemplate to perform a db operation
  • the operation fails (throws an exception)

The resulting thread state is:

  • one thread has the following (abbreviated) stacktrace:
    GenericObjectPool.borrowObject() line: 1118
    PoolingDataSource.getConnection() line: 106
    BasicDataSource.getConnection() line: 881
    JdbcUtils.extractDatabaseMetaData(..)
    SQLErrorCodesFactory.getErrorCodes(DataSource) line: 213
    SQLErrorCodeSQLExceptionTranslator.setDataSource(DataSource) line: 141
    SQLErrorCodeSQLExceptionTranslator.(DataSource) line: 104
    MyBatisExceptionTranslator.initExceptionTranslator() line: 84
    MyBatisExceptionTranslator.translateExceptionIfPossible(RuntimeException) line: 70
    SqlSessionTemplate.insert(...)

This thread already holds one connection from the pool, and is waiting for another.

  • 4 other threads are stuck waiting on synchronized method MyBatisExceptionTranslator.initExceptionTranslator while holding a connection from the pool
  • the other threads are waiting for an initial connection from the pool.

This situation does occur only under some specific conditions:

  • no connection from the datasource has yet encountered an SQL exception (ie translator is not yet initialized)
  • a group of threads (larger than connection pool size) simultaneously perform an operation that throws an SQL exception
  • the operation is not marked @transactional (ie spring transaction manager has not bound a connection to the current thread)

While the situation is somewhat unusual, it is not impossible. In particular, something like the arrival of a batch of messages on a JMS queue may trigger a set of threads to simultaneously try to perform the same SQL operation.

There is unfortunately no easy work-around for this; the most obvious way is to eager-initialize the exception-translator rather than lazy-initialize it. Unfortunately, while the MyBatisExceptionTranslator constructor does take a boolean parameter that indicates whether to lazy-init or not, the only caller of the constructor is SqlSessionTemplate which hard-codes "true" (lazy-init).

It would be nice if the <settings> element could be used to specify whether lazy-init is wanted or not - and for safety, to default lazy-init to false.

SpringManagedTransactionFactory always ignore autoCommit

I'm running mybatis-spring 1.2.2, I need to control transaction manually for part of DAO (for integration with datagrid via JTA), transaction is controlled by SqlSession, SqlSession is got from sqlSessionFactory manually in code, and sqlSessionFactory is a spring bean:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="configLocation" value="config/mybatis-config.xml" />
    <property name="dataSource" ref="dataSource" />
</bean>

When logs show "DEBUG [main] org.mybatis.spring.transaction.SpringManagedTransaction: JDBC Connection com.mysql.jdbc.JDBC4Connection @ 7f946a32 will not be managed by Spring", my rollback doesn't work.

From org.mybatis.spring.transaction.SpringManagedTransactionFactory's javadoc: "If Spring's transaction handling is active it will no-op all commit/rollback/close calls assuming that the Spring transaction manager will do the job. If it is not it will behave like JdbcTransaction.", to my understanding, it should be rolled back.

Part code of SpringManagedTransactionFactory:

public Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit) {
    return new SpringManagedTransaction(dataSource);
}

autoCommit is ignored, always. Is it a bug?

I'll push my whole testing project to GitHub if necessary.

Currently, a workaround is to set JdbcTransactionFactory as transactionFactory, configuration:

<bean id="transactionFactory" class="org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory" />
<bean id="sqlSessionFactory2" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="configLocation" value="config/mybatis-config-spring.xml" />
    <property name="dataSource" ref="dataSource" />
    <property name="transactionFactory" ref="transactionFactory" />
</bean>

2nd cache doesn't work properly

Description

I am using mybatis-spring-1.2.2, mybatis-3.2.8, spring-4.1.4.1.1.RELEASE
I have a spring bean call deviceMapper like this.

public interface DeviceMapper {
    @Select("SELECT * FROM Device")
    List<Device> all1();

    List<Device> all2();
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.springapp.mvc.mapper.DeviceMapper">
    <cache readOnly="false"/>

    <select id="all2" resultType="device">
      SELECT * FROM Device
    </select>

</mapper>

And then I inject it and use it in a test method like this, and the XML query work well.

public class DeviceMapperTest {
    @Autowired
    private DeviceMapper deviceMapper;

    void test() {
        deviceMapper.all1();    // JDBC connection open
        deviceMapper.all1();    // connection open again, no cache hit

        deviceMapper.all2();    // JDBC connection open
        deviceMapper.all2();    // cache hit
    }
}

Log Output

DEBUG - Creating a new SqlSession
DEBUG - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3312a3e2] was not registered for synchronization because synchronization is not active
DEBUG - Fetching JDBC Connection from DataSource
DEBUG - JDBC Connection [ProxyConnection[PooledConnection[com.mysql.jdbc.JDBC4Connection@de62b5b]]] will not be managed by Spring
DEBUG - ==> Preparing: SELECT * FROM Device
DEBUG - ==> Parameters:
DEBUG - <== Total: 3
DEBUG - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3312a3e2]
DEBUG - Returning JDBC Connection to DataSource
DEBUG - Creating a new SqlSession
DEBUG - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@19256710] was not registered for synchronization because synchronization is not active
DEBUG - Fetching JDBC Connection from DataSource
DEBUG - JDBC Connection [ProxyConnection[PooledConnection[com.mysql.jdbc.JDBC4Connection@de62b5b]]] will not be managed by Spring
DEBUG - ==> Preparing: SELECT * FROM Device
DEBUG - ==> Parameters:
DEBUG - <== Total: 3
DEBUG - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@19256710]
DEBUG - Returning JDBC Connection to DataSource
DEBUG - Creating a new SqlSession
DEBUG - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@920693f] was not registered for synchronization because synchronization is not active
DEBUG - Cache Hit Ratio [com.springapp.mvc.mapper.DeviceMapper]: 0.0
DEBUG - Fetching JDBC Connection from DataSource
DEBUG - JDBC Connection [ProxyConnection[PooledConnection[com.mysql.jdbc.JDBC4Connection@de62b5b]]] will not be managed by Spring
DEBUG - ==> Preparing: SELECT * FROM Device
DEBUG - ==> Parameters:
DEBUG - <== Total: 3
DEBUG - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@920693f]
DEBUG - Returning JDBC Connection to DataSource
DEBUG - Creating a new SqlSession
DEBUG - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@592ba177] was not registered for synchronization because synchronization is not active
DEBUG - Cache Hit Ratio [com.springapp.mvc.mapper.DeviceMapper]: 0.5
DEBUG - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@592ba177]

If I using a @CacheNamespace in mapper interface instead of <cache /> in mapper XML, it became the annotation query work well.

    void test() {
        deviceMapper.all1();    // JDBC connection open
        deviceMapper.all1();    // cache hit

        deviceMapper.all2();    // JDBC connection open
        deviceMapper.all2();    // connection open again, no cache hit
    }

If my usage is incorrect and misunderstand the cache usage, please let me know.

mybatis-spring OSGi bundle does not specify MyBatis dependency version

I am using mybatis-spring-1.2.1 bundle in a spring 3/Mybatis 3.1.1 project. My application bundles are deployed on shared JBoss Fuse (ESB) environment that different teams are working on.

I faced a problem when anther team installed a newer version of the Mybatis on the fuse server (i.e. Mybatis 3.2.5). And because mybatis-spring-1.2.1 bundle does not mandate a version/range of versions of Mybatis. So the fuse server automatically picked the newer installed version when resolve/starting mybatis-spring-1.2.1 bundles needed by my application bundles.

As a result my application started to throw excpetion in mapping/encoding. I did a code fix and my code runs fine noewith Mybatis 3.2.5, but I want a way/workaround to make sure that my bundles will always use the same versions of mybatis-spring and Mybatis . the ones I tested my application against.

or this is an issue mybatis-spring that will be fixed?

byteman usage prevents jd8 builds

Usage of byteman currently prevents use of travis ci to generate jdk8 build. Therefore, for time being do not attempt to add jdk8 to travis-ci until this is resolved.

How to enable mybatis scan after bean post (just when the applicationContext initialized)

mybatis provide simple cache integration defined in mybatis mapper xml. but it has some problem that the cache integrated sometimes is not initialized completed while the application context is loading.
if we bring in some @PostConstruct annotation to construct the spring bean it will throw nullpointerException while the cache instance could not be found. so how could I enable the beanpost way for mybatis especially for @mapperscan support. and through some configuration, the mybatis will invoke the initialize operation after the applicationContext completed. I just remembered some article referred such before but I could not know how to invoke that. so hope mybatis team could help me. for the cache instance sometimes is build through spring.

Interceptor plugin not working at an Spring project

I've coded a plugin with:

@Intercepts ({@Signature (type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}),
                @Signature (type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})
})
public class MyBatisPlugin implements Interceptor {...

At the sqlSessionFactory I have:

        <property name="plugins">
            <array>
                <bean class="xxx.mybatis.plugin.MyBatisPlugin"/>
            </array>
        </property>

but the Intercepts is not working, and the only method that gets called of the interceptor (allways) is the plugin method. The intercep method is not called at all.

The project is with Spring 3.2, MyBatis 3.1.1 and mybatis-spring 1.1.1.

Any idea what am I doing wrong?

Underlying DB connection is not released eagerly on Transaction Suspend

If we look at hibernate suspend method in org.springframework.orm.hibernate3.SpringSessionSynchronization then in suspend method it actively releases the DB connection. MyBatis fails to do so and say if i suspend the transaction and have a operation running for 1 minute thinking that my connection is released while actually it is still hooked up , then i run out of connections under heavy load.
Ideally it should release DB connection on suspend and reaquire from pool on resume.

Not able to set settings on mybatis-spring

I defined my org.mybatis.spring.SqlSessionFactoryBean as follows:

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
    </bean>

But I did not find a way to add the settings describing in here http://mybatis.github.io/mybatis-3/configuration.html#settings

Tried to use "configurationProperties" but no luck. Example:

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configurationProperties">
            <props>
                <prop key="lazyLoadingEnabled">true</prop>
                <prop key="aggressiveLazyLoading">true</prop>
                <prop key="logPrefix">JustTesting</prop>
            </props>
        </property>
    </bean>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.