Nice idea and seems to work. 
I changed to Integer version, because as you all said it is recommended and
timestamp is sligthly less safe.
So I have this now:

Index.class

public class Index {

        @Inject
        private PersonRepository personRepo;
        
        @Property
        private Person person;
        
        @CommitAfter
        void onSuccess() {
        }
        
        void onActivate(Integer personId, Integer version) {
                if(person == null) {
                        person = personRepo.get(personId);
                }
                if(person.getVersion() != version) {
                        throw new RuntimeException("ERROR!");
                }
        }
        
        Integer[] onPassivate() {
                return new Integer[] { person.getId(), person.getVersion() };
        }
}

Index.tml:

<t:form>
        <t:textfield t:value="person.name" />                   
        <t:submit />
</t:form>



--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Tapestry-Hibernate-optimistic-locking-tp5718413p5718425.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to