-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem excluding child inserts from optimistic locking.
PostPosted: Mon Jun 07, 2010 12:24 pm 
Newbie

Joined: Mon Jul 07, 2008 12:31 pm
Posts: 5
Hi, I'm having trouble stopping updates to a collection affecting the version of the parent entity, where I would expect @OptimisticLock(excluded = true) to do the trick. I'm using JPA, Hibernate EntityManager 3.4.0.GA.

The model features
- Unidirectional many-to-one child-parent relationship.
- The child class has a reference to its parent.
- The parent class does not have a collection of children.

The pseudo-code for the add-child operation is:

begin transaction;
find Parent;
create Child;
child.setParent(parent);
persist(child);
commit transaction;

When I execute this concurrently I get a StaleObjectStateException, as each operation tries to lock the parent. I tried exclusion from optimistic lock in the child's annotation:
Code:
   @ManyToOne(targetEntity = Parent.class)
    @OptimisticLock(excluded=true)
    @JoinColumn(name = "parentId")
    @ForeignKey(name = "fk_child_parent")
    public Parent getParent() {
        return parent;
    }

without success. I then added a collection of children to the parent, with exclusion specified there too:
Code:
    @OneToMany
    @OptimisticLock(excluded = true)
    Set<Child> getChildren() {
        return children;
    }

also without success.

Can anyone tell me what's wrong here?

Thanks,
Richard


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.