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

The Java ORM framework Bee uses transactional methods

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article introduces the knowledge of "how to use transactions in Java ORM framework Bee". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

/ / single stroke operation. The transaction is automatically committed by default.

To commit multiple operations in a single transaction, you can use:

Transaction transaction=SessionFactory.getTransaction ()

Transaction.begin (); / / transaction starts

/ /. Put multiple operations here

Transaction.commit (); / / commit the transaction and end the transaction

Specific examples are as follows:

Public static void main (String [] args) {

Suid suid=BeeFactory.getHoneyFactory () .getSuid ()

SuidRich suidRich=BeeFactory.getHoneyFactory () .getSuidRich ()

Orders orders = new Orders ()

Orders.setUserid ("Test1008-1")

Orders.setTotal (new BigDecimal ("10.0")

Suid.insert (orders); / / single stroke operation, submitted by default

Orders orders2 = new Orders ()

Orders2.setUserid ("Test1008-2")

Orders2.setTotal (new BigDecimal ("0.0"))

Suid.insert (orders2)

Transaction transaction=SessionFactory.getTransaction ()

Transaction.begin (); / / transaction starts

Orders orders3=suidRich.selectOne (orders)

Orders3.setTotal (new BigDecimal ("5.0"))

Orders orders4=suidRich.selectOne (orders2)

Orders4.setTotal (new BigDecimal ("5.0"))

SuidRich.update (orders3)

SuidRich.update (orders4)

Transaction.commit (); / / commit the transaction and end the transaction

}

This is the end of the content of "Java ORM Framework Bee using transaction methods". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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: 300

*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

Internet Technology

Wechat

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

12
Report