Another problem occurs when you use SSH. When you query data in the database and save the data, you can insert a record again. Check the log records and find that this object has been treated as transient when it is saved. So it is natural that hibernate uses insert instead of update, but it is okay to use the same logic in other experiments before, this is only because many functions are provided.
The logic is like this: Find an object by Id in the action, modify some values, and then call the business layer to save it. In this case, the first query and subsequent save operations are not in a transaction. It is possible that when the session is saved, the association with the object has been released, and the object becomes transient. I have been thinking for a long time, change the logic to a new object in the action, assign values to the id and the attributes to be modified, assign the object to the business layer, query the object in the business layer, modify the object, and save the object, in addition, the business layer method is configured as a transaction to solve the problem.
The configuration method is as follows:
[Html]
<Bean id = "transactionManager" class = "org. springframework. orm. hibernate3.HibernateTransactionManager">
<Property name = "sessionFactory" ref = "sessionFactory"> </property>
</Bean>
<Tx: advice id = "txAdvice" transaction-manager = "transactionManager">
<Tx: attributes>
<Tx: method name = "*"/>
</Tx: attributes>
</Tx: advice>
<Aop: config> www.2cto.com
<Aop: pointcut id = "myPointcut" expression = "bean (floorService) | bean (tableService)"/>
<Aop: advisor advice-ref = "txAdvice" pointcut-ref = "myPointcut"/>
</Aop: config>
FloorService and tableService are the objects at the business layer. <tx: method name = "*"/> configures each method in the object as a transaction.