使用Hibernate和MySQL(全局和本地)进行Spring事务管理 [英] Spring Transaction Management with Hibernate and MySQL, Global and Local

查看:70
本文介绍了使用Hibernate和MySQL(全局和本地)进行Spring事务管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MySQL Server 5.1,Spring 3.0.5和Hibernate 3.6开发Web应用程序.我使用Springs事务管理.我是新手,所以如果我问一个容易回答的问题,请耐心等待.:-)

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 answer. :-)

1)我了解了全球(xa)和本地交易.正确的是,全局事务是指在不同资源(例如不同数据库)上执行数据操作的事务.而且本地事务仅在一种资源(数据库)上执行数据操作.?

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)是否可以与Hibernate进行全球交易?在Spring参考文档中,我读到了以下内容:您还可以轻松地使用Hibernate本地事务,如以下示例所示.在这种情况下,您需要定义一个Hibernate LocalSessionFactoryBean,您的应用程序代码将使用该Hibernate来获取Hibernate.会话实例." 这就是为什么我认为Hibernate事务可能始终是本地事务,而我却没有发现其他事情.

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)为什么可以在Hibernate中使用MyISAM表?他们不支持事务,而我认为Hibernate需要事务吗?我真的不明白.起初我以为这是不可能的-但是为什么可以用Hibernate创建MyISAM表并使用MyISAM方言呢?这是如何运作的???Hibernate是否需要事务处理?我以为使用Hibernate需要使用InnoDB.

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.

感谢您的回答!:-)

推荐答案

  1. 是的,JTA是Java中用于XA事务的API,它使用两阶段提交协议执行全球交易.如果您需要确保多个资源上事务的一致性,那么JTA是Java中合适的工具.

  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.

休眠可以与JTA一起使用.与普通原始资源本地事务相比,建立起来要困难得多,由于两阶段提交的性质,通常使用更多的资源,并且实现质量在数据库供应商和驱动程序之间有所不同,因此仅在需要时才使用它.(例如,JTA类可以与MS SQL Server一起使用,但是此功能只能通过一组存储过程来实现.其他资源可能不支持所有标准,例如,不允许暂停事务并稍后恢复.如果您不需要它,请省去麻烦.)

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.)

您可以将MyISAM与Hibernate一起使用,但是事务将无法进行.Hibernate将正常启动和提交事务,而MyISAM存储引擎将静默忽略这些事务,因此所有内容将直接进入磁盘.除非有理由不要使用默认的存储引擎InnoDB.

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.

这篇关于使用Hibernate和MySQL(全局和本地)进行Spring事务管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆