Home » Support » Forum » Transaction isolation support?

Transaction isolation support?


I am looking at using ObjectDB for our new project, and its looking good so far. But I have been unable to find any documentation about how transaction isolation is handled.

For example: What happens If I am reading data in transaction A, and then transaction B commits while A is reading. (Especially if using LAZY fetch sub object). Do I always just get the list of objects as it looks when the fetch start?




Every EntityManager manages its own memory objects (which represent database objects). Therefore, if an entity object is retrieved by one EntityManager and then updated in the database by another EntityManager, the first EntityManager may still have an old version of that entity object.

In that case, an exception will be thrown on attempt to store a different update of that specific object using the first EntityManager, due the default optimistic locking (unless disabled in the configuration).

You can use refresh to get an up to date version of an object.

To avoid using the same object by different users concurrently (even for read) you can use explicit locking.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

That was not exactly what I meant: Take the following example:

We have a User class and a Book class, and each User have a list of books which the user own defined as

@OneToMany(fetch=FetchType.LAZY) List<Book>bookList;

(And in this example, there is only 1 object in the User table, just to make the explanation more easy).

Now imagine the following where A and B are 2 different entity managers. (Which in our implementation will be 2 Different threads, serving 2 different http request)

B: Fetch user.  (User user=em1.find(User.class,1)).

A: Fetch user (User user=em2.find(User.class,1));

B: Create and save a new Book, and add it as a book to the user.
B: Save user.
A: Get list of users books.

Now the question: Does the list of books fetched by A include the new book added by B?. And does this change if FetchType.LAZY changes to FetchType.EAGER?

In a SQL database, A and B would run in their own transaction, and the answer would thus depend on the the selected isolation level for the transaction in A.


It depends when the list of books is retrieved by A.

If the collection is owned by User (i.e. not mapped by, as you wrote), then it is part of the User object, and will be retrieved with the User instance before B changes the list.

If the collection is mapped by, then it depends on the fetch setting.

Anyway, you can always refresh the User instance to get up to date content.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login