Dan Diephouse wrote:
Heya, I think I'm probably doing something pretty stupid here, but I'm having a few problems using Jackrabbit in a multithreaded environment. If you can imagine I have this scenario:

Thread #1 running inside my unit test which is doing stuff to the repository all in one session. Thread #2 which is reading stuff inside the repository and updating some nodes

I think occasionally these threads collide though and start modifying the same node. Then I starting getting things like:

javax.jcr.RepositoryException: failed to create transient state: there's already a property state instance with id 1d038015-6c48-4654-a685-1dcf57a6bf6f/{http://www.jcp.org/jcr/1.0}mixinTypes: there's already a property state instance with id 1d038015-6c48-4654-a685-1dcf57a6bf6f/{http://www.jcp.org/jcr/1.0}mixinTypes at org.apache.jackrabbit.core.PropertyImpl.getOrCreateTransientItemState(PropertyImpl.java:97) at org.apache.jackrabbit.core.PropertyImpl.restoreTransient(PropertyImpl.java:143) at org.apache.jackrabbit.core.ItemImpl.restoreTransientItems(ItemImpl.java:734)
   at org.apache.jackrabbit.core.ItemImpl.save(ItemImpl.java:1233)
   at org.apache.jackrabbit.core.SessionImpl.save(SessionImpl.java:849)
...
Caused by: org.apache.jackrabbit.core.state.ItemStateException: there's already a property state instance with id 1d038015-6c48-4654-a685-1dcf57a6bf6f/{http://www.jcp.org/jcr/1.0}mixinTypes at org.apache.jackrabbit.core.state.SessionItemStateManager.createTransientPropertyState(SessionItemStateManager.java:629) at org.apache.jackrabbit.core.PropertyImpl.getOrCreateTransientItemState(PropertyImpl.java:90)
   ... 42 more

Or:

javax.jcr.RepositoryException: failed to create transient state: there's already a property state instance with id 1d038015-6c48-4654-a685-1dcf57a6bf6f/{http://www.jcp.org/jcr/1.0}uuid: there's already a property state instance with id 1d038015-6c48-4654-a685-1dcf57a6bf6f/{http://www.jcp.org/jcr/1.0}uuid at org.apache.jackrabbit.core.PropertyImpl.getOrCreateTransientItemState(PropertyImpl.java:97) at org.apache.jackrabbit.core.PropertyImpl.restoreTransient(PropertyImpl.java:143) at org.apache.jackrabbit.core.ItemImpl.restoreTransientItems(ItemImpl.java:734)
   at org.apache.jackrabbit.core.ItemImpl.save(ItemImpl.java:1233)
   at org.apache.jackrabbit.core.SessionImpl.save(SessionImpl.java:849)
....
Caused by: org.apache.jackrabbit.core.state.ItemStateException: there's already a property state instance with id 1d038015-6c48-4654-a685-1dcf57a6bf6f/{http://www.jcp.org/jcr/1.0}uuid at org.apache.jackrabbit.core.state.SessionItemStateManager.createTransientPropertyState(SessionItemStateManager.java:629) at org.apache.jackrabbit.core.PropertyImpl.getOrCreateTransientItemState(PropertyImpl.java:90)
   ... 42 more

If the second thread was accessing a node created by the first thread and the node wasn't saved yet, would that explain these errors?

Any ideas how to avoid this???


One other thing. Those exceptions are from thread #2. I get this exception from thread #1:

org.springframework.dao.ConcurrencyFailureException: Invalid item state; nested exception is javax.jcr.InvalidItemStateException: /activities: the node cannot be saved because it has been modified externally.

Caused by: javax.jcr.InvalidItemStateException: /activities: the node cannot be saved because it has been modified externally.
   at org.apache.jackrabbit.core.NodeImpl.makePersistent(NodeImpl.java:969)
at org.apache.jackrabbit.core.ItemImpl.persistTransientItems(ItemImpl.java:687)
   at org.apache.jackrabbit.core.ItemImpl.save(ItemImpl.java:1198)
   at org.apache.jackrabbit.core.SessionImpl.save(SessionImpl.java:849)

Cheers,
- Dan

--
Dan Diephouse
MuleSource
http://mulesource.com | http://netzooid.com/blog

Reply via email to