由于本人最近刚刚开始使用SpringMVC+Mybatis,遇到了一个问题:
后台日志
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Creating SqlSession with JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@254ed667]
DEBUG: [java.sql.Connection.(28)debug] - ooo Connection Opened
DEBUG: [org.mybatis.spring.transaction.SpringManagedTransaction.(28)debug] - JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@254ed667] will not be managed by Spring
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@345dbcb5] was not registered for synchronization because synchronization is not active
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Executing: SELECT a.* FROM CRM_USER a WHERE a.username = ? AND a.password = ?
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Parameters: canon(String), canon(String)
DEBUG: [java.sql.ResultSet.(28)debug] - <== Columns: ID, USERNAME, PASSWORD, NICKNAME, CREATE_DATE, STATE, REMARKS
DEBUG: [java.sql.ResultSet.(28)debug] - <== Row: 1, canon, canon, 卡农, 2015-04-28 00:00:00.0, U, null
DEBUG: [com.alibaba.druid.pool.PreparedStatementPool.(123)put] - {conn-10001, pstmt-20000} enter cache
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Closing no transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@345dbcb5]
DEBUG: [java.sql.Connection.(28)debug] - ooo Connection Opened
DEBUG: [org.mybatis.spring.transaction.SpringManagedTransaction.(28)debug] - JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@254ed667] will not be managed by Spring
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@345dbcb5] was not registered for synchronization because synchronization is not active
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Executing: SELECT a.* FROM CRM_USER a WHERE a.username = ? AND a.password = ?
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Parameters: canon(String), canon(String)
DEBUG: [java.sql.ResultSet.(28)debug] - <== Columns: ID, USERNAME, PASSWORD, NICKNAME, CREATE_DATE, STATE, REMARKS
DEBUG: [java.sql.ResultSet.(28)debug] - <== Row: 1, canon, canon, 卡农, 2015-04-28 00:00:00.0, U, null
DEBUG: [com.alibaba.druid.pool.PreparedStatementPool.(123)put] - {conn-10001, pstmt-20000} enter cache
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Closing no transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@345dbcb5]
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Creating SqlSession with JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@254ed667]
DEBUG: [java.sql.Connection.(28)debug] - ooo Connection Opened
DEBUG: [org.mybatis.spring.transaction.SpringManagedTransaction.(28)debug] - JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@254ed667] will not be managed by Spring
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5d233a8e] was not registered for synchronization because synchronization is not active
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Executing: insert into CRM_USER (ID, USERNAME, PASSWORD, NICKNAME, CREATE_DATE, STATE, REMARKS) values (?, ?, ?, ?, ?, ?, ?)
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Parameters: 334455(Long), null, null, null, null, null, null
DEBUG: [com.alibaba.druid.pool.PreparedStatementPool.(123)put] - {conn-10001, pstmt-20001} enter cache
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Closing no transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5d233a8e]
DEBUG: [org.mybatis.spring.transaction.SpringManagedTransaction.(28)debug] - JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@254ed667] will not be managed by Spring
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5d233a8e] was not registered for synchronization because synchronization is not active
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Executing: insert into CRM_USER (ID, USERNAME, PASSWORD, NICKNAME, CREATE_DATE, STATE, REMARKS) values (?, ?, ?, ?, ?, ?, ?)
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Parameters: 334455(Long), null, null, null, null, null, null
DEBUG: [com.alibaba.druid.pool.PreparedStatementPool.(123)put] - {conn-10001, pstmt-20001} enter cache
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Closing no transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5d233a8e]
问题1:数据库中有没有插入数据呢?
数据库中插入了数据,这点我也没有想明白?
危险点(1):context:component-scan设置全局扫描
修改点:
注意web.xml的执行顺序 context-param -> listener -> filter -> servlet
个人认为Spring也恰巧利用了这一点,利用listener先去加载service层的bean,然后为controller加载成bean提供依赖注入。
这也是Spring设计完美的地点
通过【org.springframework.web.context.ContextLoaderListener】扫描对应路径下的@Service等注解的
<context:component-scan base-package="com.zcrm.service" />
通过【org.springframework.web.servlet.DispatcherServlet】执行Controller注入
<!-- controller包自动注入 -->
<context:component-scan base-package="com.zcrm.controller" >
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
危险点(2):拦截器方式配置事务,容易配置错误
(2-1):expression="execution(* *..*SVImpl.*(..))" 的使用
第一个【*】:任意返回值类型
第二个【*】:任意包名
第一个【..】:通配包路径 可以有0个或者多个包路径
第三个【*】:任意字符+SVImpl的class
第四个【*】:任意方法名
第二个【..】:通配方法可以有0个或者多个参数
(2-2):事务的传播级别
1、PROPAGATION_REQUIRED:如果存在一个事务,则支持当前事务。如果没有事务则开启。
2、PROPAGATION_SUPPORTS:如果存在一个事务,支持当前事务。如果没有事务,则非事务的执行。
3、PROPAGATION_MANDATORY:如果已经存在一个事务,支持当前事务。如果没有一个活动的事务,则抛出异常。
4、PROPAGATION_REQUIRES_NEW:总是开启一个新的事务。如果一个事务存在,则将这个存在的事务挂起。
5、PROPAGATION_NOT_SUPPORTED:总是非事务地执行,并挂起任何存在的事务。
6、PROPAGATION_NEVER:总是非事务地执行,如果存在一个活动事务,则抛出异常。
7、 PROPAGATION_NESTED:如果一个活动的事务存在,则运行在一个嵌套的事务中,如果没有活动事务,则按TransactionDefinition.PROPAGATION_REQUIRED属性执行
2、PROPAGATION_SUPPORTS:如果存在一个事务,支持当前事务。如果没有事务,则非事务的执行。
3、PROPAGATION_MANDATORY:如果已经存在一个事务,支持当前事务。如果没有一个活动的事务,则抛出异常。
4、PROPAGATION_REQUIRES_NEW:总是开启一个新的事务。如果一个事务存在,则将这个存在的事务挂起。
5、PROPAGATION_NOT_SUPPORTED:总是非事务地执行,并挂起任何存在的事务。
6、PROPAGATION_NEVER:总是非事务地执行,如果存在一个活动事务,则抛出异常。
7、 PROPAGATION_NESTED:如果一个活动的事务存在,则运行在一个嵌套的事务中,如果没有活动事务,则按TransactionDefinition.PROPAGATION_REQUIRED属性执行
<!-- 拦截器方式配置事务 -->
<!-- 配置事务传播级别 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="merge*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
<tx:method name="put*" propagation="REQUIRED" />
<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
<tx:method name="count*" propagation="SUPPORTS" read-only="true" />
<tx:method name="find*" propagation="SUPPORTS" read-only="true" />
<tx:method name="list*" propagation="SUPPORTS" read-only="true" />
<tx:method name="*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<!-- 只对业务逻辑层实施事务 -->
<aop:pointcut id="txPointcut"
expression="execution(* *..*SVImpl.*(..))" />
<!-- Advisor定义,切入点和通知分别为txPointcut、txAdvice -->
<aop:advisor pointcut-ref="txPointcut" advice-ref="txAdvice" />
</aop:config>
在这里特别感谢【开涛】:http://jinnianshilongnian.iteye.com/
修改后的效果:
后台日志
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Creating SqlSession with JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@2b399081]
DEBUG: [java.sql.Connection.(28)debug] - ooo Connection Opened
DEBUG: [org.mybatis.spring.transaction.SpringManagedTransaction.(28)debug] - JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@2b399081] will be managed by Spring
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7e6dbc7f]
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Executing: insert into CRM_USER (ID, USERNAME, PASSWORD, NICKNAME, CREATE_DATE, STATE, REMARKS) values (?, ?, ?, ?, ?, ?, ?)
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Parameters: 2(Long), null, null, null, null, null, null
DEBUG: [com.alibaba.druid.pool.PreparedStatementPool.(123)put] - {conn-10001, pstmt-20000} enter cache
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7e6dbc7f]
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7e6dbc7f]
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7e6dbc7f]
DEBUG: [java.sql.Connection.(28)debug] - ooo Connection Opened
DEBUG: [org.mybatis.spring.transaction.SpringManagedTransaction.(28)debug] - JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@2b399081] will be managed by Spring
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7e6dbc7f]
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Executing: insert into CRM_USER (ID, USERNAME, PASSWORD, NICKNAME, CREATE_DATE, STATE, REMARKS) values (?, ?, ?, ?, ?, ?, ?)
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Parameters: 2(Long), null, null, null, null, null, null
DEBUG: [com.alibaba.druid.pool.PreparedStatementPool.(123)put] - {conn-10001, pstmt-20000} enter cache
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7e6dbc7f]
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7e6dbc7f]
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7e6dbc7f]
后台日志:关闭SqlSession,但是没有事务的提交
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Creating SqlSession with JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@2b399081]DEBUG: [java.sql.Connection.(28)debug] - ooo Connection Opened
DEBUG: [org.mybatis.spring.transaction.SpringManagedTransaction.(28)debug] - JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@2b399081] will be managed by Spring
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3cc472f2]
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Executing: SELECT a.* FROM CRM_USER a WHERE a.username = ? AND a.password = ?
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Parameters: canon(String), canon(String)
DEBUG: [com.alibaba.druid.pool.PreparedStatementPool.(123)put] - {conn-10001, pstmt-20001} enter cache
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3cc472f2]
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3cc472f2]
问题2:为什么这个地方还会开启事务?
求大神解决
实践(1):测试事务回滚
@RequestMapping(value={"/test"},method=RequestMethod.GET)
public String test(BOCrmUser BOCrmUser) {
String flag = "error";
try {
IUserSV.deleteByPrimaryKey(1l);//id=1
IUserSV.insert(BOCrmUser);//id=2 2已经存在了,会爆主键重复的异常
//问题:1的数据有没有被删除
flag = "success";
} catch (Exception e) {
e.printStackTrace();
}
return flag;
}
结果:1的数据被删除了,因为删除的操作和新增的操作不再一个事务中
日志:
注意SqlSession
新增的时候SqlSession是[org.apache.ibatis.session.defaults.DefaultSqlSession@5751de43]
删除的时候SqlSession是[org.apache.ibatis.session.defaults.DefaultSqlSession@474c8cd6]
注意事务提交
新增的时候,连接打开,事务提交
删除的时候,连接打开,事务没有提交
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Creating SqlSession with JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@3e5d464f]
DEBUG: [java.sql.Connection.(28)debug] - ooo Connection Opened
DEBUG: [org.mybatis.spring.transaction.SpringManagedTransaction.(28)debug] - JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@3e5d464f] will be managed by Spring
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5751de43]
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Executing: delete from CRM_USER where ID = ?
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Parameters: 1(Long)
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5751de43]
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5751de43]
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5751de43]
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Creating SqlSession with JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@3e5d464f]
DEBUG: [java.sql.Connection.(28)debug] - ooo Connection Opened
DEBUG: [org.mybatis.spring.transaction.SpringManagedTransaction.(28)debug] - JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@3e5d464f] will be managed by Spring
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@474c8cd6]
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Executing: insert into CRM_USER (ID, USERNAME, PASSWORD, NICKNAME, CREATE_DATE, STATE, REMARKS) values (?, ?, ?, ?, ?, ?, ?)
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Parameters: 2(Long), null, null, null, null, null, null
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@474c8cd6]
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@474c8cd6]
org.springframework.dao.DuplicateKeyException:
### Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: 违反唯一约束条件 (ZCRM.PK_CRM_USER)
DEBUG: [java.sql.Connection.(28)debug] - ooo Connection Opened
DEBUG: [org.mybatis.spring.transaction.SpringManagedTransaction.(28)debug] - JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@3e5d464f] will be managed by Spring
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5751de43]
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Executing: delete from CRM_USER where ID = ?
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Parameters: 1(Long)
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5751de43]
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5751de43]
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5751de43]
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Creating SqlSession with JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@3e5d464f]
DEBUG: [java.sql.Connection.(28)debug] - ooo Connection Opened
DEBUG: [org.mybatis.spring.transaction.SpringManagedTransaction.(28)debug] - JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@3e5d464f] will be managed by Spring
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@474c8cd6]
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Executing: insert into CRM_USER (ID, USERNAME, PASSWORD, NICKNAME, CREATE_DATE, STATE, REMARKS) values (?, ?, ?, ?, ?, ?, ?)
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Parameters: 2(Long), null, null, null, null, null, null
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@474c8cd6]
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@474c8cd6]
org.springframework.dao.DuplicateKeyException:
### Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: 违反唯一约束条件 (ZCRM.PK_CRM_USER)
实践(2):将删除(REQUIRED)和新增(
REQUIRED
)封装到一个新方法update(
REQUIRED
)中
public void update(BOCrmUser record){
this.deleteByPrimaryKey(1l);//删除id=1
this.insert(record);//新增id=2,主键冲突
}
@RequestMapping(value={"/update"},method=RequestMethod.GET)
public String update(BOCrmUser BOCrmUser) {
String flag = "error";
try {
IUserSV.update(BOCrmUser);
flag = "success";
} catch (Exception e) {
e.printStackTrace();
}
return flag;
}
结果
(2):1的数据没有被删除,事务回滚
日志
(2)
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Creating SqlSession with JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@3e5d464f]
DEBUG: [java.sql.Connection.(28)debug] - ooo Connection Opened
DEBUG: [org.mybatis.spring.transaction.SpringManagedTransaction.(28)debug] - JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@3e5d464f] will be managed by Spring
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5b57358d]
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Executing: delete from CRM_USER where ID = ?
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Parameters: 1(Long)
DEBUG: [com.alibaba.druid.pool.PreparedStatementPool.(123)put] - {conn-10001, pstmt-20000} enter cache
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5b57358d]
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5b57358d] from current transaction
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Executing: insert into CRM_USER (ID, USERNAME, PASSWORD, NICKNAME, CREATE_DATE, STATE, REMARKS) values (?, ?, ?, ?, ?, ?, ?)
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Parameters: 2(Long), null, null, null, null, null, null
DEBUG: [com.alibaba.druid.pool.PreparedStatementPool.(123)put] - {conn-10001, pstmt-20001} enter cache
INFO : [org.springframework.beans.factory.xml.XmlBeanDefinitionReader.(315)loadBeanDefinitions] - Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
INFO : [org.springframework.jdbc.support.SQLErrorCodesFactory.(126)<init>] - SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5b57358d]
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Transaction synchronization closing SqlSession
DEBUG: [java.sql.Connection.(28)debug] - ooo Connection Opened
DEBUG: [org.mybatis.spring.transaction.SpringManagedTransaction.(28)debug] - JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@3e5d464f] will be managed by Spring
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5b57358d]
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Executing: delete from CRM_USER where ID = ?
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Parameters: 1(Long)
DEBUG: [com.alibaba.druid.pool.PreparedStatementPool.(123)put] - {conn-10001, pstmt-20000} enter cache
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5b57358d]
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5b57358d] from current transaction
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Executing: insert into CRM_USER (ID, USERNAME, PASSWORD, NICKNAME, CREATE_DATE, STATE, REMARKS) values (?, ?, ?, ?, ?, ?, ?)
DEBUG: [java.sql.PreparedStatement.(28)debug] - ==> Parameters: 2(Long), null, null, null, null, null, null
DEBUG: [com.alibaba.druid.pool.PreparedStatementPool.(123)put] - {conn-10001, pstmt-20001} enter cache
INFO : [org.springframework.beans.factory.xml.XmlBeanDefinitionReader.(315)loadBeanDefinitions] - Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
INFO : [org.springframework.jdbc.support.SQLErrorCodesFactory.(126)<init>] - SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5b57358d]
DEBUG: [org.mybatis.spring.SqlSessionUtils.(28)debug] - Transaction synchronization closing SqlSession
事务同步关闭SqlSession
[org.apache.ibatis.session.defaults.DefaultSqlSession@5b57358d]
org.springframework.dao.DuplicateKeyException:
### Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: 违反唯一约束条件 (ZCRM.PK_CRM_USER)
### The error may involve com.zcrm.dao.BOCrmUserMapper.insert-Inline
### The error occurred while setting parameters
### Cause: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: 违反唯一约束条件 (ZCRM.PK_CRM_USER)
; SQL []; ORA-00001: 违反唯一约束条件 (ZCRM.PK_CRM_USER)
org.springframework.dao.DuplicateKeyException:
### Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: 违反唯一约束条件 (ZCRM.PK_CRM_USER)
### The error may involve com.zcrm.dao.BOCrmUserMapper.insert-Inline
### The error occurred while setting parameters
### Cause: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: 违反唯一约束条件 (ZCRM.PK_CRM_USER)
; SQL []; ORA-00001: 违反唯一约束条件 (ZCRM.PK_CRM_USER)
相关推荐
MyBatis与Spring框架结合使用时,可以实现声明式事务管理,简化了事务处理的代码。 这个压缩包中的“3.1.1jar”可能是Spring、SpringMVC和MyBatis的特定版本的库文件,这些库文件是集成这三个框架所必需的。确保...
1. **Spring框架**:Spring的核心是依赖注入,它允许开发者声明式地管理对象及其依赖关系,减少了代码的耦合度。同时,Spring还提供了AOP支持,可以方便地实现日志、事务管理等功能。除此之外,Spring还包含了对JDBC...
在IT行业中,SpringMVC、MyBatis以及声明式事务管理是Java Web开发中的关键组件。这个项目结合了这三个核心技术,构建了一个高效、稳定的后端系统。以下将详细阐述这些技术及其相互配合的工作原理。 首先,...
Spring是Java领域的一个核心框架,它提供了一种声明式事务管理、依赖注入、AOP(面向切面编程)等功能,极大地简化了Java应用程序的开发。在本项目中,Spring主要负责以下任务: - **依赖注入(Dependency Injection...
Spring框架提供了SpringMVC和Mybatis的整合方式,如使用Spring的声明式事务管理,可以在Spring配置中统一管理事务的开始、提交、回滚。同时,Spring还可以通过@Autowired注解自动注入Mybatis的Mapper接口,简化了...
Spring框架提供了对JDBC的高级封装,可以简化数据库操作,同时支持声明式和编程式的事务管理,确保数据的一致性。 在Idea中整合这些技术,我们需要以下步骤: 1. 创建Maven项目,配置pom.xml文件,引入相关依赖。 2...
4. **Spring事务管理**:Spring的@Transactional注解可以实现声明式事务管理,即在方法上添加此注解,Spring会自动进行事务的开启、提交、回滚等操作。这使得开发者无需手动管理事务,降低了出错的可能性,也使得...
- Spring的主要目标是简化企业级应用的开发过程,提供了一种替代传统Java EE的方式,使得开发者可以通过声明式的方式来配置和管理应用程序的组件。Spring通过提供一种基于配置而非硬编码的方式来管理组件之间的依赖...
- **事务管理**:支持编程式和声明式事务管理,确保数据一致性。 3. **myBatis**: - **SQL映射**:将SQL语句与Java代码分离,提升可维护性。 - **动态SQL**:通过XML或注解实现动态生成SQL,灵活应对各种查询...
- **事务管理**:Spring提供了声明式事务管理,使得开发者可以方便地在代码中处理事务,无需显式调用commit或rollback。 2. **SpringMVC框架** - **模型-视图-控制器**:SpringMVC是Spring框架的一个模块,负责...
3. **事务管理**:提供编程式和声明式事务管理,确保数据一致性。 4. **Spring MVC集成**:与SpringMVC无缝结合,提供统一的配置和上下文管理。 **MyBatis** MyBatis是一个轻量级的持久层框架,它解决了Java开发中...
3. **事务管理**: Spring提供声明式事务管理,可以在SpringMVC的配置中设置事务边界,确保数据操作的一致性。例如,使用`@Transactional`注解标记在Service方法上,Spring会自动管理事务的开启、提交或回滚。 4. **...
这是一个基于Java技术栈的Web应用开发整合包,主要包含了Spring、SpringMVC、MyBatis、Maven和easyUI这五个关键组件。下面将详细解释这些技术及其整合方式。 **Spring框架**:Spring是一个全面的Java企业级应用开发...
在SpringMVC中,Mybatis可以通过Spring的事务管理器进行事务控制,实现声明式事务。SpringMVC的ModelAndView对象可以用来传递数据到Mybatis查询结果,而Mybatis的ResultMap则可以方便地映射查询结果到Java对象。...
它与Spring框架结合使用时,可以实现声明式事务管理,提高代码的健壮性。 **jd-gui** 是一个Java反编译工具,用于查看Java字节码并将其转换为源代码形式。开发者可以使用jd-gui来了解已有的类库或者分析运行中的...
Spring MVC提供了一种声明式异常处理机制,支持多种视图技术如JSP、FreeMarker等,并且可以与Spring其他模块(如Spring AOP、Spring Security)无缝集成。 MyBatis是一个轻量级的持久层框架,它将SQL语句直接写在...
Mybatis与Spring框架结合使用时,可以实现声明式事务管理,进一步提升开发效率。 将SpringMVC、Spring和Mybatis集成在一起,首先需要配置Spring的上下文,声明Bean并管理其生命周期。然后,通过Spring的DataSource...
在SSM整合中,Mybatis作为数据访问层,与Spring结合可以实现声明式事务管理。 在SSM整合例子中,你可以期待以下步骤: 1. **环境准备**:首先确保已安装JDK、Maven和Tomcat等基础环境,设置好环境变量。 2. **...
本框架就是基于IDEA搭建的一个集成框架,它整合了Spring、SpringMVC和MyBatis三大流行框架,并利用Maven进行项目管理和依赖管理,为开发者提供了一站式的解决方案。 【Spring框架】 Spring作为Java企业级应用的核心...
Mybatis通过XML或注解配置,可以轻松地处理复杂的数据库操作,并且与Spring框架结合使用时,可以实现声明式事务管理。 4. **模板项目设置**:这个模板项目已经预先配置好了这些框架的集成,包括Spring的上下文配置...