交易问题

时间:2015-12-24 20:28:52

标签: mysql spring jpa weblogic12c

我想要做的是保存用户,然后保存餐馆实体。我认为这很容易,但似乎我没理解。

    userService.save(user); //this one runs just fine
    selectedRestaurant.getEmployees().add(user);
    restaurantService.save(selectedRestaurant); //exception

两者之间的关系是@OneToMany。没有使用事务注释。 我认为第一个打开一个事务并关闭它,第二个打开一个事务。但在尝试保存餐厅后,我得到了这个:

    [[ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG org.hibernate.engine.jdbc.internal.LogicalConnectionImpl  - Obtaining JDBC connection
[[ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG org.hibernate.engine.jdbc.internal.LogicalConnectionImpl  - Obtained JDBC connection
[[ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl  - Skipping aggressive release due to registered resources
[[ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG org.hibernate.jpa.spi.AbstractEntityManagerImpl  - Mark transaction for rollback
[[ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'] INFO  org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl  - HHH000106: Forcing container resource cleanup on transaction completion
[[ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG org.hibernate.engine.jdbc.spi.SqlExceptionHelper  - could not log warnings
java.sql.SQLException: Statement has already been closed

为什么这会回滚?

我正在尝试使用spring data jpa(1.9.2.RELEASE),weblogic 12c,mysql 5.6.17。 如果在weblogic中启用了相关的Emulate Two-Phase Commit。

你能否给我建议如何正确地做到这一点?

1 个答案:

答案 0 :(得分:1)

自动生成用户ID。 save方法无法在没有id的实体和dto之间建立连接。