Spring programmatic transaction management issues

Updated on technology 2024-05-02
8 answers
  1. Anonymous users2024-02-08

    1.Choose programmatic or declarative transaction management: Programmatic transaction management is often appropriate when you have only a few transaction operations.

    For example, if you have a web application where only specific update operations require transactions, you may be reluctant to set up transactions using Spring or other technologies. In this case, it may be a good idea to use a transactiontemplate. Only programmatic transaction management can explicitly set the transaction name.

    On the other hand, if you have a large number of transaction operations in your application, then declarative transaction management is often worthwhile. It decouples transaction management from business logic, and it's not difficult to configure in Spring. In our development, there are relatively few places where transactions are generally used, and I think programmatic transactions are sufficient.

    Use declarative transactions, for applications like ours that require a lot of speed. Instead, it can cause performance problems. 2:

    It is recommended that transactions be at a high level, such as a function on the service (especially for applications like ours that SNS is not like a money-linked financial system, which does not require high data accuracy), and the underlying DAO can ignore transactions (in general, the database itself can be processed at the default transaction management level), otherwise transaction nesting may occur, increasing program complexity. Transactions are often closely related to business rules, and when the business logic changes, it means a significant change in the DAO. The system size reaches a certain level, and the risk of modification is considerable.

    The advantage of Spring transactions is that the existing DAO is not changed, and the existing service beans only need to be configured or modified as little as possible to achieve the transactional effect. At the same time, the transaction is unified in the service layer, and the system structure is clearer.

  2. Anonymous users2024-02-07

    There should be a lot of problems.

  3. Anonymous users2024-02-06

    The bottom annihilation faction uses the AOP principleSpring provides an interface, PlatformTransactionManager, which stands for Transaction Manager, and different frameworks provide different implementation classes.

    Concept:How transactions are managed in the process of being called between multiple thing methods.

    (2).isolution: the level of thing isolation

    In the case of high concurrency, if the isolation of transactions is not considered, the following three problems will occur: dirty reads, non-repeatable reads, and virtual reads.

    For the above problems, see MySQL Transaction Management.

    Setting the transaction isolation level can solve the above problem:

    (3).timeout: the timeout period

    (4).readonly: whether it is read-only

    (5).rollbackfor: rollback

    (6).norollbackfor: does not roll back

    Step 1:Create a transaction manager.

    Step 2:Configure notification (enhanced) (i.e. transactional) search.

    Step 3:Configure entry points and facets.

    1. Create a configuration class txconfig:

    2. Testing:

  4. Anonymous users2024-02-05

    There are two ways to do this: encoding; Declarative transaction management.

    The essence of declarative transaction management based on AOP technology is to intercept before and after the method is executed, then create and join the transaction before the target method starts, and commit or roll back the transaction according to the execution status after the target method is executed.

    There are two ways of declarative transaction management: XML configuration file-based approach; The other is to annotate @transactional business methods and apply transaction rules to business logic.

    4 Characteristics of Transactions:

    Atomicity: All operations on the database in a transaction are an indivisible sequence of operations, either all or all.

    Consistency: Data is not corrupted by the execution of a transaction.

    Isolation: The execution of one transaction without interference from other transactions (processes). Transactions that are executed concurrently do not interfere with each other.

    Durability: Once a transaction is committed, its changes to the database are permanent.

  5. Anonymous users2024-02-04

    This is achieved in two ways.

    1.Declarative Transaction 2Programmatic transactions.

  6. Anonymous users2024-02-03

    Looking at what has been written so much, there is a lot of pressure, and I can only tell you that I don't know!

  7. Anonymous users2024-02-02

    You need to know the nature of a transaction.

    Transaction four characteristics (abbreviated as acid).

    1. Atomicity: All operations in a transaction are inseparable in the database, and either all operations are completed or none are executed.

    2. Consistency: The execution results of several transactions executed in parallel must be consistent with the results of serial execution in a certain order.

    3. Isolation: The execution of the transaction is not interfered with by other transactions, and the intermediate results of the transaction execution must be transparent to other transactions.

    4. Durability: For any committed transaction, the system must ensure that the transaction changes to the database are not lost, even if the database fails.

    If you use a transaction in inserts() and you call methods A and B in this method, then if either method A or B has an exception, then the whole transaction will be rolled back.

    Of course, you can configure declarative transactions in Spring, so you don't have to do it manually.

    It only needs to be configured in the configuration file.

  8. Anonymous users2024-02-01

    Control transactions in the configuration file.

Related questions
5 answers2024-05-02

Don't close the session at the end of using currentsession, that is, don't write it; This will allow you to use the session object you have created in the current thread. When using OpenSession, you must remember to close the session. As for the transaction not being committed, check whether your transaction configuration is correct and whether there is an exception that causes the transaction to be rolled back.

10 answers2024-05-02

The guy upstairs said the concept. I'll say more.

IOC is a container, and everything that is created is created in a container. You can think of this thing as something like a factory model. >>>More

8 answers2024-05-02

The beans in the Spring configuration file and the Spring framework itself will be dynamically created and loaded, and you don't need to manually load them yourself.

9 answers2024-05-02

This is very easy to implement, save this expression in the database, and of course read the configuration file every time it starts up (when the server starts). >>>More