Le blog de pingou

To content | To menu | To search

Bioinformatique

Entries feed - Comments feed

Monday, June 18 2012

Java JPA and rollback on MySQL

source.png

We (b8e5n and I) have been fighting for too long for this, so there it is dear lazy web.

Using the eclipse JPA (Java Persistence API) to connect to a MySQL database you might experienced some troubles.

Using the following piece of code:

transaction = manager.getTransaction();
transaction.begin();
try {
     // Add here your logic
     transaction.commit();
} finally {
     if (transaction.isActive()) {
           transaction.rollback();
     }
}

We kept running into the fact that the rollback never happened. The commit was performed or at least started and if something was going wrong at the database level (like an already existing primary key), the data already commited to the database would remain in there.

So yay for the half-commited data :-s

It took us a while but we finally ended up finding the solution on a lost corner of the web:

** Please take special note for MySQL database users: do make sure that your tables are InnoDB tables instead of MyISAM. If not, rollback will not occur.

Switching from MyISAM to InnoDB solved the problem for us, the transaction is either fully commited or not at all.

Hope this can help.

Tuesday, March 13 2012

Python notes to self

source.png

Small python optimization that I should really follow

Continue reading...

Wednesday, October 12 2011

Jena, virtuoso and option transitive

Virtuoso has a specific syntax option(transitive) which need a little trick for Jena.

Continue reading...

Monday, March 23 2009

Getting rJava/JRI to work:

Because I just spent way too much time to get this working, if you ever try to get the JRI from rJava working and you have the error:

Cannot find JRI native library!

Please make sure that the JRI native library is in a directory listed in java.library.path

What you need to do is:
In you java script print your java.library.path:

System.out.println(System.getProperty("java.library.path"));

Check that the folder /usr/lib64 is in
Then do:

cp /usr/lib64/R/library/rJava/jri/libjri.so  /usr/lib64/

It is this file that JRI is looking for and it will solved the problem.

Well now I'm facing:

Creating Rengine (with arguments)
R_HOME is not set. Please set all required environment variables before
running this program.
Unable to start R

and this even if I made export R_HOME=/usr/lib64/R/ before...

How to waste time....

For those that are interested, rJava/JRI enables object binding between R and Java or Java and R, it's probably pretty cool... once you have it working