开发者

Spring Transaction Management with Hibernate and MySQL, Global and Local

Im working on developing a webapplication with MySQL Server 5.1, Spring 3.0.5 and Hibernate 3.6. I use Springs Transaction Management. Im a newbie, so please be patient with me if I ask a question which is easy to a开发者_如何学编程nswer. :-)

1) I read about global (xa) and local transactions. Is it correct, that global transactions mean transactions, which execute dataoperations on different resources (like different databases). And that local transactions execute dataoperations on only one resource (database).?

2) Is it possible to have global transactions with Hibernate? In the Spring Reference Documentation I read this: "You can also use Hibernate local transactions easily, as shown in the following examples. In this case, you need to define a Hibernate LocalSessionFactoryBean, which your application code will use to obtain Hibernate Session instances." Thats why I think that Hibernate transactions are maybe always local and I did not find anything else about it.

3) Why is it possible to use MyISAM tables with Hibernate? They dont support Transactions and I think Hibernate requires Transactions? I really don't understand this. At first I thought it wouldn't be possible - but why is it then possible to create MyISAM Tables with Hibernate and use a MyISAM Dialect? How does this work??? Does Hibernate require transaction or doesnt it? I thought for using Hibernate you need to use InnoDB.

Thanks for answering! :-)


  1. Yes, JTA, the API for XA transactions in Java, uses a two-phase commit protocol to perform global transactions. If you need to ensure transaction consistency over multiple resources, JTA is the proper tool in Java.

  2. Hibernate does work with JTA. It is quite a bit harder to set up than plain vanilla resource local transactions, generally uses more resources due to the nature of two-phase commit, and the implementation quality varies between database vendors and drivers, so only use it if you have to. (For example, JTA kinda sorta works with MS SQL Server, but this functionality is only glued on through a set of stored procedures. Other resources may not support all of the standard, for example not allow a transaction to be paused and later resumed. If you don't need it, save yourself the trouble.)

  3. You can use MyISAM with Hibernate, but transactions won't work. Hibernate will start and commit transactions normally, which the MyISAM storage engine will ignore silently, so everything will go straight to disk. Use the default storage engine, InnoDB, unless you have a reason not to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜