I found a solution.
The problem is that I was not using transactions...
Just surround my code in a tm.begin() and tm.commit() and it works fine.
I get my tm using the jboss tm locator:
TransactionManager tm = TransactionManagerLocator.locateTransactionManager();
tm.begin();
// get and set variables here
tm.commit();
Is this the right way to go?