Friday, March 11, 2011

Hibernate Cache

Hibernate is a well-know persistence framework in the  Java world, it comes with a wonderful API to ease application communication with the database. Caching is a mechanism that stores data so that future requests for that data can be served faster. It’s a good point for performance when there are a lot of requests for the same stuff . 

Hibernate comes with 3 caching mechanisms to resolve this issue.
First Level Cache
A hibernate session is a unit of work that’s corresponding to a DB transaction. When doing operations on entities, these latters are not stored immediately in DB but wait until the session commits. The hibernate session is hence representing the first level cache and it’s enabled by default.
Second Level Cache
A hibernate SessionFactory aims to create sessions, initializes JDBC connections and pool them. The second level cache lives in the SessionFactory level so all session can share it. This is why it’s called a process scoped cache.
The second level cache is not enabled by default. One has to configure the cache strategy for hibernate entities and the cache provider that will be a third party caching API like EHCache.
Query Cache
This is related to second level cache and is used for caching queries with parameters. It has to be configured like the second level cache.
To know if the application is hitting the cache, you can configure it in the session factory configuration file and begin your unit tests to get an idea of performance.

Oracle SOA 11g domain issue in R1 PS2

Many weeks ago, I installed a virtual machine of Oracle SOA Suite 11g R1 PS2. Recently, I got time to try it and I got many suprises in the starting of SOA domain.

1. The domain cannot be started and an error message was got : Could not locate enough heap memory.
Searched using google and somebody said the SUN JDK has issue to support large memory. I am not sure whether it is right or not totally as I never got such issue before as BEA WebLogic domain never reserve too much memory. I modified the PermMaxSize and it really solved the starting issue.

2. Got error message in the console after the server was started : Servlet container could not initialized.
Searched on the internet with Google and found it came from the application of Oracle and nothing wrong for the domain.

3. Got SQLException int the console
Searched again with Google and found it is related with the connection testing of datasource and will not affect anything.