Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is a Hibernate JDBC transaction?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what is Hibernate JDBC transaction". In daily operation, I believe many people have doubts about what Hibernate JDBC transaction is. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubt about "what Hibernate JDBC transaction is!" Next, please follow the editor to study!

The initialize () method of the Hibernate class

The initialize () method forces Hibernate to load immediately the objects and collections associated with the specified entity. There are several other useful but uncomfortable common methods in the Hibernate class.

Lazy attributes in the mapping file

In Hibernate3, the lazy attribute of the class element defaults to true, and if it is not needed, it needs to be specified as lazy= "false". Otherwise, the object returned by the operation load will throw an exception. In addition, the lazy attribute can be specified for entity attributes in Hibernate3.

Hibernate JDBC transaction and JTA transaction

Hibernate itself has no transaction management function, which depends on the transaction management function of JDBC or JTA. In the Hibernate configuration file, if you do not explicitly specify the configuration of the factory class attribute hibernate.transaction.factory_class of Transaction, the default is JDBC transaction:

Org.hibernate.transaction.JDBCTransactionFactory

After the Session is obtained through SessionFactory, the JDBC Connection instance associated with the Session is set to false.

Special note: if the database does not support transactions, such as tables in MySQL's MyISAM engine, declaring transactions will not work. To make the table of MySQL5 support transactions, you can specify that the engine type of the table is InnoDB. If you are studying or studying, you will still use PostgreSQL 8.3or DB2 or Oracle at present.

Hibernate JDBC transactions are always associated with a database connection (or a Session).

JTA transactions can span multiple data connections (or multiple Session), and these connections can also be connections to different databases, and JTA transactions are typically managed by containers. Programming simply defines the boundaries of JTA transactions at the beginning and end of multiple operating units.

Special note: if JTA transactions are used, you can no longer use JDBC-style transactions to manage the operations of each Session, otherwise errors will occur. For the sake of program versatility, applications are generally built using Hibernate JTA transactions, which use any environment. Of course, you can also use transaction agents to add transaction control to the operation methods of each JDBC. This also brings great convenience for the program to be ported to JTA container transactions in the future. In fact, you can now use Spring transaction management, which is very combined with Hibernate.

At this point, the study of "what is a Hibernate JDBC transaction" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report