Wednesday, July 19, 2017

Adding Oracle to Local Maven Repository and As a Maven Dependency

Oracle is not having a jar file in the global maven repository due to some legal issues. It has to be always downloaded and required to be added as lib for your applications or need to be configure in your app server.

Below is the way to include it in your local maven repository.

1. Download the ojdbc jar file. For example ojdbc7.jar

2. Issue the below command

mvn install:install-file -Dfile={location of downloaded jar}  -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion={version} -Dpackaging=jar

//example
mvn install:install-file -Dfile=/home/chamara/ojdbc7.jar  -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.2.0 -Dpackaging=jar

3. Then add the below dependency

example :
 <dependency>  
      <groupId>com.oracle</groupId>  
      <artifactId>ojdbc7</artifactId>  
      <version>12.1.0.2.0</version>  
 </dependency>  

Thursday, January 26, 2017

PESSIMISTIC_READ/WRITE with JPA, Hibernate and Oracle

In an enterprise application we have used pessimistic locking in some of the entity retrieval and persistence to avoid dirty reads and writes due to the extreme concurrent access. As we know, JPA provide both PESSIMISTIC_READ and PESSIMISTIC_WRITE capabilities which use shared lock and exclusive lock respectively.

If you make the sql query enabled with persistence settings, you can see the underlying queries of both lock types are going to be the same which make use of oracle's FOR UPDATE clause with the respective select queries. When browse through the articles on this, I found that it is allowed for the JPA provider to provide the PESSIMISTIC_WRITE, even the PESSIMISTIC_READ mode explicitly set in the queries. But it is not permitted the other way around.

Below article, provides a good insight into the pessimistic locking with different database providers.

https://vladmihalcea.com/2015/02/24/hibernate-locking-patterns-how-do-pessimistic_read-and-pessimistic_write-work/