JpaSagaRepository and Transactions

Axon: 1.1.2
Hibernate Entity Manager: 3.6.7.Final
PostgreSQL JDBC: 9.0-801.jdbc4

I am receiving the following error after restarting a system which has
placed a few entries into a saga: org.postgresql.util.PSQLException:
Large Objects may not be used in auto-commit mode.

It is failing on line 132 of JpaSagaRepository when it retrieves
values for the AssociationValueEntry entity in the "initialize"
method.

The EJB3 specification states that auto commit must be enabled. The
source for Ejb3Configuration in Hibernate even checks to ensure that
the auto commit is enabled. The solution is that the call to the
database must be wrapped in a transaction. However, since the code in
JpaSagaRepository is called as a @PostConstruct simply placing a
"@Transactional" may not work if it hasn't been configured yet.

I'm at a loss to a solution. I have not encountered this issue with
Oracle or MySQL but PostgreSQL needs a transaction when retrieving
Lobs.

Any guidance to this problem would be greatly appreciated.

Thanks,
Seamus

Hi Seamus,

that’s a nasty one. Perhaps the (quick) solution is a simple one: I could implement lazy initialization upon the first invocation.
I’m still considering changing the implementation of the Saga Manager a bit, so that it no longer requires pre-loading all the association values.

One thing that’s on my mind: the value part of an AssociationValue can be any serializable value. Personally, I have never needed anything else than String (or AggregateIdentifier, which can be converted to a String). Does anyone see a good reason not to limit both key and value of the AssociationValue to the String type?

Cheers,

Allard

Thanks Allard!

After I submitted my message I thought about the lazy initialisation
so I did just that... I copied the JpaSagaRepository locally and
removed the @PostConstruct and added an override of the add() and
find() methods to initialise the associations.

Thanks again!
Seamus

Hi Seamus,

could you send a patch? It’ll help reduce my dev time for this issue.

Cheers,

Allard

Hi Allard,

Here is the diff.

Thanks,
Seamus

JpaSagaRepository.diff (2.42 KB)