Professional Documents
Culture Documents
----------
ORM - Object relational mapping
Configuration
SessionFactory
Session
Tx
----------------------------------------
--------------------------------------------------------------------
Entity : The java class which is mapped with DB table is called as ENtity class.
2) annotations
@Entity
@Table
@Id
@Column
@GeneratedValue
DB_Table : BOOK_DTLS
COLUMN NAMES: BOOK_ID, BOOK_NAME , BOOK_PRICE
@Data
@Entity
@Table("BOOK_DTLS)
public class BookDtlsEntity{
@Id
@GeneratedValue
@Column(name="BOOK_ID")
private Integer bookId;
@Column(name="BOOK_NAME")
private String bookName;
@Column(name="BOOK_PRICE")
private Double bookPrice;
}
<bean id="transactionManager"
class="pkg.HibernateTransactionManager">
<property name="sessionFactory" ref="sf" />
</bean>
i.set(10);
i.get();
Transaction management
======================
What is transaction?
--------------------
The unit amount of work we are doing is called as transaction.
JDBC : setAutoCommit(true);
Hibernate: setAutoCommit(false);
If we are using hibernate for persistent operations, programmer is responsible to
manage transactions with database.
I - isolation: Individual
D - durability : Permanent
2) Declarative approach: In xml config file, we will specify for which methods
transaction should be applied.
Note: For DB select operations transactions are not required. For DB non-select
operations (insert, update, delete) trasactions are mandatory.
read-only
read-write
isolation
new or propagation
phanton-read
dirty-read
Locking
Declarative Tx Management
--------------------------
<aop:config>
<aop:pointcut
expression="execution(* pkg.EmployeeDaoImpl.create(..))"
id="createOperation">
</aop:pointcut>
<aop:advisor advice-ref="txAdvice"
pointcut-ref="createOperation">
</aop:advisor>
</aop:config>
emp table
emp_dept table
HibernateTemplate