HibernateTemplate and transaction
Hello
That is, for example, I have this code:
Quote:
getHibernateTemplate (). save (user);
getHibernateTemplate (). save (order1);
getHibernateTemplate (). save (order2);
I think some of these three operations united into a single transaction? ie that if the least of these operations do a mistake then all three do the same please give proper suggestion thanks
Re: HibernateTemplate and transaction
- Use the transaction management software. To do this, see TransactionCallback.
- Use a declaratory transaction management. This is done at the configuration level g. In this case, it can be a method transformation. That is, starting with the transaction method, and closes when you exit. This method has many possiblity. For example, you can specify at what exceptions should revert the transaction or to specify the transaction read only.
Re: HibernateTemplate and transaction
Remove Of hibernateTemplate of calls to of the of respective DAO, but of the of code of itself and then in a Of service. In of which, depending on of the of approach, or work of with of the of transaction of directly or of mark of through of annotation or of through of configuration, as of described of above.Usually of does of not of directly of cause of the of methods Of hibenrateTemplate. Make of the DAO, which of causes of create, which of has of delegated of this Of hibernateTemplate.save ().
Re: HibernateTemplate and transaction
for example, for of operations of with of the of orders, I have OforderService, there Of orderDAO, I appeal to Of orderService, it in of turn to Of orderDao,
and OrderDAO of example of looks of like of this:
Quote:
of public of class Of orderDAO of extends Of hibernateDaoSupport (
of public Of orderDAO () (
super ();
)
of public Of order of getOrderById (int id) (
…
)
)
Re: HibernateTemplate and transaction
based solely on the manager of the transaction, which is located in the most getHibernateTemplate (). This is the manager and determine whether it is a transaction or more. Again, it was not clear getHibernateTemplate () returns a copy, or different? If one instance, the high probability is one session, and one transaction. But specify that only in most cases. Because it is possible to set up such a code, and for different sessions and in different transactions and for all that you want. That something is his charm
Re: HibernateTemplate and transaction
Service could use several different methods of DAO. Depending on the situation, we can quickly make this method useful, and just as quickly removed from the transaction. Service should not know anything about how the interface is implemented DAO.