convertBeanToEntity => Used to convert business bean/dao into entity by BeanUtils API
Spring Core with JPA with Transaction Manager
Automating for tansaction Begin & Commit
Methods
Declarative
Using Annotations
PlatformTransactionManager
Service provider interface, has inplementations specific to backend
Transaction Metadata
Metadata about transaction, defiend by TransactionDefinition interface
Transactioanl Proxy
Object created by spring framework, wrapper over target object, uses PlatformTransactionManager
Types of Transactions
Global
Managed by app container, using Java Transaction API (JTA)
Made by using TransactionManager and injecting EntityManager
Requires extra container to perform the method
Local
Resource specific, JDBC connection is an example, extra connection is not required
Made by injecting EntityManagerFactory and creating EntityManager local
Correctness across multiple types of resources can't be assured
@Transactional annotation
It can be placed at class level, interface level or method level. Method or class level are more preferred
Spring encourages to keep the access specifier of the method as public where this annotation is used otherwise no error is raised but method will not exhibit configured transaction settings
This annotation defines the Transaction Metadata, to be given to Transaction Proxy
Transactions can be made read only using this annotation, throws exception of persist()
@PersistenceContext
Handle transactions using Spring Container EntityManager, instead of injecting EntityManagerFactory
Container managed EntityManager is created using @PersistenceContext
Transactional Scoped Persistence Context
Default for container managed EntityManager
Persistence Context is created after every method call
Extended scope Persistence Context
Default for non-container managed EntityManager
Used to share state of Entity across method calls
Using XML
Programatic (Imperative)
Transaction Propogation
Used for complex transactions
Rollback of unchecked exception is triggered by default, otherwise custom configured using rollbackFor="ExceptionName.class" attribute
Steps
Split the single physical transaction into smaller logical transactions
Physical Transaction can be started at the service layer using @Transactional
Logical transactions can be started at the database layer
Logical transactions can share the same transactional scope with the physical transaction so that, when one of logical transaction is rolled back then it rolls back the physical transaction there by all the other related logical transactions are also rolled back
Logical transactions can have the independent transactional scope, so that rollback of the one logical transaction should not hinder any other logical transaction / physical transaction