Showing posts with label jpa. Show all posts
Showing posts with label jpa. Show all posts

Saturday, August 31, 2013

@PrePersist and @PreUpdate - not working with Hibernate 4 Session and Spring

    @PrePersist and @PreUpdate annotations have their roots in JPA specification. Hibernate implements JPA specification. However, if we decide to use SessionFactory and Session instead of EntityManagerFactory and EntityManager, we will realize that mentioned annotations are ignored. Is there a way to solve the problem?

Saturday, April 20, 2013

Database deadlock example

    Some time ago I wrote about deadlock in Java language. However the problem of a deadlock can also appear in a database. The transactions are just the analogues of threads. Is a database able to recover from a deadlock? Let's check this out!

Sunday, March 3, 2013

Hibernate flush modes

    Hibernate minimizes the trips to the database in order to gain some performance. It is the flush mode that controls how many times Hibernate hits the DB when it comes to write operations. The behaviour of the flushing mechanism is customizable. It is worth to know that the proper configuration of the flush mode can have quite a big influence on the overall performance (especially while testing when the transaction is not committed).

Sunday, February 3, 2013

I am optimistic... exception!

    Java EE applications usually handle many concurrent users. This means that there must exist some strategies that keep the data consistent in case of concurrent modification of the same database row (entity). JPA2 defines two types of locking, namely Optimistic Locking (OL) and Pessimistic Locking (PL).

Saturday, January 26, 2013

@SequenceGenerator revealed

The following trio of annotations is popular in JPA applications:
@Id

@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "customer_seq")

@SequenceGenerator(name = "customer_seq", sequenceName = "CUSTOMER_SEQ") 

Monday, January 21, 2013

Basic JPA mappings

    Sometimes, when I have to add a couple of mappings to the data model I have to spend a while to recall the correlation between JPA annotations and underlying database schema. I decided to create some kind of a cheat sheet with basic JPA mappings.