Spring Transactions (@Transactional) within ObjectDB

#1

Hi,

We are using OBD with Spring and transactions are managed by Spring. Our spring service interfaces take list of objects and persist them and the interface service is marked as @Transactional.

We iterate through the list apply business validations and persist them one by one in a loop. ( Using Spring Data)

We have noticed that in a loop 1st object is persisted and then we if lookup the same object we don't get it back on lookup.

This is with transactions we are not able to retrieve the persisted object within the same transaction. It is only available after transaction commit. Ideally the lookup is also part of same transaction so it should be aware of the persisted object.

The logic works fine if i remove @Transactional attribute from my service method.
is this desirable behavior of ODB ?  I thought in the same transaction if i do a lookup on persisted object I should be able to get the reference. Thanks for your help.

 

#2

Updates to objects are always available in the same transaction also before commit.

But it is unclear which operations exactly are performed by your application and by Spring Data. If queries are involved, then it is possible to miss recent updates, because ObjectDB uses FlushModeType.COMMIT by default.

Try switching to FlushModeType.AUTO. It is less efficient but it should guarantee that queries in a transaction will reflect also uncommitted updates of that transaction.

ObjectDB Support
#3

Thanks for prompt response.

Yes typed queries are invloved for JPA Spring data which does findbyCode where code is one of the entity properties.

This was working well with ORM - Hibernate when used with Spring Data / JPA and when the same Spring Data / JPA moved to point to objectDB is giving issues.

Do you know how to FlushModeType.AUTO in ORM.xml we are not doing any annotations over our entity. Thanks in advance!

 

#4

See the links to the manual in #2 above. You should prepare the EntityManager:

    em.setFlushMode(FlushModeType.AUTO);
ObjectDB Support
#5

I think I need help here --

I thin the entity Manger property for FlushModeType is need to be specified in persistence.xml in my case and I am not able to find out the exact name in case of ObjectDB

IN case of hibernate I can use something like <property name="org.hibernate.FlushMode" value="auto" />

That's what I am looking for - Kindly advise !

 

Thanks,
Sandeep

#6

Build 2.5.2_01 adds support for enabling auto flush by default, by setting a system property:

    System.setProperty("objectdb.temp.auto-flush", "true");

before loading ObjectDB, or as a JVM argument:

> java -Dobjectdb.temp.auto-flush=true ...
ObjectDB Support

Reply