mybatis-spring事务问题
我在使用 CMT Spring 事务与 mybatis 时遇到问题,我有一个使用 2 MapperFactoryBean 插入记录的类。
插入记录时出现FOREIGN KEY约束异常;似乎两者都在不同的会话中运行,第二个无法找到新插入的 id。
在第二条记录的外键中传递 null 时;没有抛出异常,但事务也没有提交。
如果抛出任何异常,回滚工作正常。
这是我的配置
<tx:jta-transaction-manager />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="url" value="${database.url}"/>
<property name="driverClassName" value="${database.driverClassName}"/>
<property name="username" value="${database.username}"/>
<property name="password" value="${database.password}"/>
<property name="defaultAutoCommit" value="false" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
<property name="nestedTransactionAllowed" value="true" />
<property name="validateExistingTransaction" value="true" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:dataAccess-config.xml"/>
</bean>
<bean id="taskRecordMapper" class="org.mybatis.spring.MapperFactoryBean">
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
<property name="mapperInterface" value="TaskRecordMapper"/>
</bean>
<bean id="taskTagRecordMapper" class="org.mybatis.spring.MapperFactoryBean">
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
<property name="mapperInterface" value="TaskTagRecordMapper"/>
</bean>
代码片段
@Transactional(propagation= Propagation.REQUIRED)
public boolean assignTask(Object source, TaskType taskType, String description,
long assignedTo, long createdBy, long escalationId,
boolean isAssignedToGroup, long parentTaskId,
Date deadline, TaskPriority taskPriority) throws Exception
{
EntityType entityType = TaskUtil.getEntityType(source);
long entityId = TaskUtil.getIdFromObject(source);
TaskRecord newTask = new TaskRecord();
newTask.setAssignedTo((isAssignedToGroup) ? null : assignedTo);
newTask.setCategory(entityType.toString());
newTask.setCreatedBy(createdBy);
newTask.setCreatedOn(new Date());
newTask.setDeadline(deadline);
newTask.setDescription(description);
newTask.setEntityId(entityId);
newTask.setEscalationId(escalationId);
newTask.setIsAssignedToGroup(isAssignedToGroup);
newTask.setIsDeleted(false);
newTask.setModifiedBy(null);
newTask.setModifiedOn(null);
newTask.setOwner(createdBy);
newTask.setParentId((parentTaskId == 0) ? null : parentTaskId);
newTask.setPriority(taskPriority.toString());
newTask.setReferenceNo(null);
newTask.setResult(null);
newTask.setStatus(TaskStatus.InProgress.toString());
newTask.setType(taskType.toString());
boolean rValue = taskRecordMapper.insert(newTask) > 0;
if(rValue && isAssignedToGroup)
{
TaskTagRecord tag = new TaskTagRecord();
tag.setTaskId(newTask.getId());
tag.setName("RoleId");
tag.setValue(String.valueOf(assignedTo));
rValue = taskTagRecordMapper.insert(tag) > 0;
}
return rValue;
}
感谢期待
这是堆栈跟踪
org.springframework.dao.DataIntegrityViolationException: SqlSession operation; SQL []; The INSERT statement conflicted with the FOREIGN KEY constraint "FK_task_tag_task". The conflict occurred in database "TEMP", table "dbo.task", column 'id'.; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_task_tag_task". The conflict occurred in database "TEMP", table "dbo.task", column 'id'.
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:101)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.mybatis.spring.SqlSessionTemplate.wrapException(SqlSessionTemplate.java:364)
at org.mybatis.spring.SqlSessionTemplate$7$1.doInSqlSession(SqlSessionTemplate.java:344)
at org.mybatis.spring.SqlSessionTemplate.execute(SqlSessionTemplate.java:173)
at org.mybatis.spring.SqlSessionTemplate.execute(SqlSessionTemplate.java:155)
at org.mybatis.spring.SqlSessionTemplate$7.invoke(SqlSessionTemplate.java:339)
at $Proxy18.insert(Unknown Source)
at com.task.service.TaskService.assignTask(TaskService.java:184)
at com.task.service.TaskService.assignTask(TaskService.java:137)
at com.core.mapper.TaskServiceTest.main(TaskServiceTest.java:38)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_task_tag_task". The conflict occurred in database "TEMP", table "dbo._task", column 'id'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1454)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:388)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:338)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:185)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:160)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(SQLServerPreparedStatement.java:320)
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:169)
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.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:45)
at $Proxy38.execute(Unknown Source)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:22)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:51)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:29)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:75)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:43)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:118)
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:107)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:56)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:38)
at $Proxy18.insert(Unknown Source)
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.mybatis.spring.SqlSessionTemplate$7$1.doInSqlSession(SqlSessionTemplate.java:342)
... 7 more
这是调试日志
02:41:32,465 INFO main [ClassPathXmlApplicationContext] Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1bc887b: startup date [Thu May 26 02:41:32 GST 2011]; root of context hierarchy
02:41:32,512 INFO main [XmlBeanDefinitionReader] Loading XML bean definitions from class path resource [dataAccessApplicationContext.xml]
02:41:33,034 INFO main [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@173b262: defining beans [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.springframework.context.config.internalBeanConfigurerAspect,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.beans.factory.config.PropertyOverrideConfigurer#0,dataSource,transactionManager,sqlSessionFactory,managedTransactionFactory,springApplicationContext]; root of factory hierarchy
02:41:34,512 DEBUG main [Connection] ooo Connection Opened
02:41:34,659 DEBUG main [PreparedStatement] ==> Executing: select id, order_number, com_id, order_date, status, source, created_on, created_by, is_deleted, modified_on, modified_by from order WHERE ( id = ? and is_deleted = ? )
02:41:34,660 DEBUG main [PreparedStatement] ==> Parameters: 264(Long), false(Boolean)
02:41:34,699 DEBUG main [ResultSet] <== Columns: id, order_number, com_id, order_date, status, source, created_on, created_by, is_deleted, modified_on, modified_by
02:41:34,709 DEBUG main [ResultSet] <== Row: 264, 00277-100410, 1041, 2010-01-01 00:00:00.0, Pending, COMPANY A, 2011-05-24 00:21:00.337, 1, 0, null, null
02:41:34,723 DEBUG main [Connection] xxx Connection Closed
02:41:34,742 DEBUG main [Connection] ooo Connection Opened
02:41:34,747 DEBUG main [PreparedStatement] ==> Executing: insert into task (type, status, owner, description, context_id, deadline, assigned_to, parent_id, priority, escalation_id, reference_no, result, created_on, created_by, modified_on, modified_by, category, entity_id, is_deleted, is_assigned_to_group) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
02:41:34,747 DEBUG main [PreparedStatement] ==> Parameters: Investigation(String), InProgress(String), 1(Long), Please investigate this order(String), null, 2011-05-27 02:41:34.736(Timestamp), null, null, Normal(String), 1(Long), null, null, 2011-05-26 02:41:34.737(Timestamp), 1(Long), null, null, Order(String), 264(Long), false(Boolean), true(Boolean)
02:41:34,757 DEBUG main [PreparedStatement] ==> Executing: select @@identity
02:41:34,757 DEBUG main [PreparedStatement] ==> Parameters:
02:41:34,763 DEBUG main [ResultSet] <== Columns:
02:41:34,763 DEBUG main [ResultSet] <== Row: 94
02:41:34,782 DEBUG main [Connection] xxx Connection Closed
02:41:34,800 DEBUG main [Connection] ooo Connection Opened
02:41:34,803 DEBUG main [PreparedStatement] ==> Executing: insert into task_tag (name, value, task_id ) values (?, ?, ? )
02:41:34,804 DEBUG main [PreparedStatement] ==> Parameters: RoleId(String), 1(String), 94(Long)
02:41:34,842 INFO main [XmlBeanDefinitionReader] Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
02:41:34,859 INFO main [SQLErrorCodesFactory] SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
02:41:34,944 DEBUG main [Connection] xxx Connection Closed
I am having issues using CMT Spring transaction with mybatis, I have a class that uses 2 MapperFactoryBean to insert record.
When inserting records getting FOREIGN KEY constraint exception; it seems both are running in different sessions and the second one could not find the newly inserted id.
When passing null in second record's foreign key; no exception is thrown but also transaction is not committed.
Rollback is working fine if any exception is thrown.
Here is my configuration
<tx:jta-transaction-manager />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="url" value="${database.url}"/>
<property name="driverClassName" value="${database.driverClassName}"/>
<property name="username" value="${database.username}"/>
<property name="password" value="${database.password}"/>
<property name="defaultAutoCommit" value="false" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
<property name="nestedTransactionAllowed" value="true" />
<property name="validateExistingTransaction" value="true" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:dataAccess-config.xml"/>
</bean>
<bean id="taskRecordMapper" class="org.mybatis.spring.MapperFactoryBean">
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
<property name="mapperInterface" value="TaskRecordMapper"/>
</bean>
<bean id="taskTagRecordMapper" class="org.mybatis.spring.MapperFactoryBean">
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
<property name="mapperInterface" value="TaskTagRecordMapper"/>
</bean>
Code snippet
@Transactional(propagation= Propagation.REQUIRED)
public boolean assignTask(Object source, TaskType taskType, String description,
long assignedTo, long createdBy, long escalationId,
boolean isAssignedToGroup, long parentTaskId,
Date deadline, TaskPriority taskPriority) throws Exception
{
EntityType entityType = TaskUtil.getEntityType(source);
long entityId = TaskUtil.getIdFromObject(source);
TaskRecord newTask = new TaskRecord();
newTask.setAssignedTo((isAssignedToGroup) ? null : assignedTo);
newTask.setCategory(entityType.toString());
newTask.setCreatedBy(createdBy);
newTask.setCreatedOn(new Date());
newTask.setDeadline(deadline);
newTask.setDescription(description);
newTask.setEntityId(entityId);
newTask.setEscalationId(escalationId);
newTask.setIsAssignedToGroup(isAssignedToGroup);
newTask.setIsDeleted(false);
newTask.setModifiedBy(null);
newTask.setModifiedOn(null);
newTask.setOwner(createdBy);
newTask.setParentId((parentTaskId == 0) ? null : parentTaskId);
newTask.setPriority(taskPriority.toString());
newTask.setReferenceNo(null);
newTask.setResult(null);
newTask.setStatus(TaskStatus.InProgress.toString());
newTask.setType(taskType.toString());
boolean rValue = taskRecordMapper.insert(newTask) > 0;
if(rValue && isAssignedToGroup)
{
TaskTagRecord tag = new TaskTagRecord();
tag.setTaskId(newTask.getId());
tag.setName("RoleId");
tag.setValue(String.valueOf(assignedTo));
rValue = taskTagRecordMapper.insert(tag) > 0;
}
return rValue;
}
Thanks in anticipation
Here is the Stacktrace
org.springframework.dao.DataIntegrityViolationException: SqlSession operation; SQL []; The INSERT statement conflicted with the FOREIGN KEY constraint "FK_task_tag_task". The conflict occurred in database "TEMP", table "dbo.task", column 'id'.; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_task_tag_task". The conflict occurred in database "TEMP", table "dbo.task", column 'id'.
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:101)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.mybatis.spring.SqlSessionTemplate.wrapException(SqlSessionTemplate.java:364)
at org.mybatis.spring.SqlSessionTemplate$7$1.doInSqlSession(SqlSessionTemplate.java:344)
at org.mybatis.spring.SqlSessionTemplate.execute(SqlSessionTemplate.java:173)
at org.mybatis.spring.SqlSessionTemplate.execute(SqlSessionTemplate.java:155)
at org.mybatis.spring.SqlSessionTemplate$7.invoke(SqlSessionTemplate.java:339)
at $Proxy18.insert(Unknown Source)
at com.task.service.TaskService.assignTask(TaskService.java:184)
at com.task.service.TaskService.assignTask(TaskService.java:137)
at com.core.mapper.TaskServiceTest.main(TaskServiceTest.java:38)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_task_tag_task". The conflict occurred in database "TEMP", table "dbo._task", column 'id'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1454)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:388)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:338)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:185)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:160)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(SQLServerPreparedStatement.java:320)
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:169)
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.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:45)
at $Proxy38.execute(Unknown Source)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:22)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:51)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:29)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:75)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:43)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:118)
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:107)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:56)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:38)
at $Proxy18.insert(Unknown Source)
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.mybatis.spring.SqlSessionTemplate$7$1.doInSqlSession(SqlSessionTemplate.java:342)
... 7 more
Here is the DEBUG log
02:41:32,465 INFO main [ClassPathXmlApplicationContext] Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1bc887b: startup date [Thu May 26 02:41:32 GST 2011]; root of context hierarchy
02:41:32,512 INFO main [XmlBeanDefinitionReader] Loading XML bean definitions from class path resource [dataAccessApplicationContext.xml]
02:41:33,034 INFO main [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@173b262: defining beans [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.springframework.context.config.internalBeanConfigurerAspect,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.beans.factory.config.PropertyOverrideConfigurer#0,dataSource,transactionManager,sqlSessionFactory,managedTransactionFactory,springApplicationContext]; root of factory hierarchy
02:41:34,512 DEBUG main [Connection] ooo Connection Opened
02:41:34,659 DEBUG main [PreparedStatement] ==> Executing: select id, order_number, com_id, order_date, status, source, created_on, created_by, is_deleted, modified_on, modified_by from order WHERE ( id = ? and is_deleted = ? )
02:41:34,660 DEBUG main [PreparedStatement] ==> Parameters: 264(Long), false(Boolean)
02:41:34,699 DEBUG main [ResultSet] <== Columns: id, order_number, com_id, order_date, status, source, created_on, created_by, is_deleted, modified_on, modified_by
02:41:34,709 DEBUG main [ResultSet] <== Row: 264, 00277-100410, 1041, 2010-01-01 00:00:00.0, Pending, COMPANY A, 2011-05-24 00:21:00.337, 1, 0, null, null
02:41:34,723 DEBUG main [Connection] xxx Connection Closed
02:41:34,742 DEBUG main [Connection] ooo Connection Opened
02:41:34,747 DEBUG main [PreparedStatement] ==> Executing: insert into task (type, status, owner, description, context_id, deadline, assigned_to, parent_id, priority, escalation_id, reference_no, result, created_on, created_by, modified_on, modified_by, category, entity_id, is_deleted, is_assigned_to_group) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
02:41:34,747 DEBUG main [PreparedStatement] ==> Parameters: Investigation(String), InProgress(String), 1(Long), Please investigate this order(String), null, 2011-05-27 02:41:34.736(Timestamp), null, null, Normal(String), 1(Long), null, null, 2011-05-26 02:41:34.737(Timestamp), 1(Long), null, null, Order(String), 264(Long), false(Boolean), true(Boolean)
02:41:34,757 DEBUG main [PreparedStatement] ==> Executing: select @@identity
02:41:34,757 DEBUG main [PreparedStatement] ==> Parameters:
02:41:34,763 DEBUG main [ResultSet] <== Columns:
02:41:34,763 DEBUG main [ResultSet] <== Row: 94
02:41:34,782 DEBUG main [Connection] xxx Connection Closed
02:41:34,800 DEBUG main [Connection] ooo Connection Opened
02:41:34,803 DEBUG main [PreparedStatement] ==> Executing: insert into task_tag (name, value, task_id ) values (?, ?, ? )
02:41:34,804 DEBUG main [PreparedStatement] ==> Parameters: RoleId(String), 1(String), 94(Long)
02:41:34,842 INFO main [XmlBeanDefinitionReader] Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
02:41:34,859 INFO main [SQLErrorCodesFactory] SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
02:41:34,944 DEBUG main [Connection] xxx Connection Closed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 DEBUG 日志来看,交易似乎从未启动。我认为问题在于默认情况下未启用
@Transactional
。您需要将
添加到 Spring xml 文件中。From the DEBUG log, it looks like a tx never started. I think the issue is that
@Transactional
is not enabled by default. You need to add<tx:annotation-driven transaction-manager="transactionManager" />
to your Spring xml file.不确定这是否能解决问题,但肯定有问题:
这意味着您正在使用 JTA,就像将事务处理委托给应用程序服务器一样。
这
意味着您正在使用 Spring 事务处理。我看不到这个 bean 在任何地方被明确引用,但这可能会导致一些问题。你想走哪条路,委托给应用程序服务器(你是在真正的应用程序服务器上运行还是使用 Tomcat/Jetty?),还是让 Spring 处理事务?如果是后者,则删除 JTA 指令;如果是后者,则删除 transactionManager 定义(或将类更改为 JTA 事务管理器)。
Not sure that this will solve the issue but something is definitely wrong with:
This implies you are using JTA, as in delegate transaction handling to the application server.
And also you have
Which means you are using Spring transaction handling. I cannot see this bean being referenced anywhere explicitly, but probably this causes some problems. Which way you want to go, delegate to appserver (are you running on a real appserver even or using Tomcat/Jetty?), or let Spring handle the transactions? If the latter, remove the directive to JTA, of the other, remove the transactionManager definition (or change the class to JTA transaction manager).