Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The Java ORM framework Bee uses transactional methods

Shulou Source: shulou.com Published: 2022-06-02 08:58:37 10月04日 Update

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!

Tags: Transactions methods frameworks content more knowledge practicality learning next examples dilemmas multiple actual situations articles cases editing websites industries processes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Tech Info macOS NVidia vpn