-->
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: Need help with locking
PostPosted: Fri Oct 01, 2010 10:52 am 
Newbie

Joined: Mon Jan 25, 2010 9:16 pm
Posts: 2
I've been trying to learn more abount the new lock capabilities in JPA2. I'm reading [url=http://weblogs.java.net/blog/2009/07/30/jpa-20-concurrency-and-locking]Carol McDonald's[url] article. Unfortunately I'm unable to run any of the example given by Carol in this article.
Trying to reproduce the example given in figure 2 I've written the following code:
Code:
public class Main {

    public static void main(String[] args) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory(
                "JPALockingPU");

        EntityManager em0 = emf.createEntityManager();
        EntityManager em1 = emf.createEntityManager();

        System.out.println("em0 = " + em0);
        System.out.println("em1 = " + em1);
       
        em0.getTransaction().begin();
        em1.getTransaction().begin();

        EntityOne p0 = em0.find(EntityOne.class, 1);
        EntityTwo e1 = em1.find(EntityTwo.class, 1);

        EntityOne p1 = e1.getEntityTwo();
        em1.lock(p1, LockModeType.OPTIMISTIC);

        p0.setTeste(p0.getTeste() + 1);
        e1.setTeste(e1.getTeste() + 1);

        em0.getTransaction().commit();
        em1.getTransaction().commit();

        em0.close();
        em1.close();
    }

}

This is a desktop app (of course) and I'm running this code with Hibernate 3.5.3 and PostgreSQL 8.1. According Carol's article em1's transaction should not commit as e1 is locked and it was updated by em0's transaction but it simple don't happen. Looking the generated sql, it doesn't even check e1's version atribute. What am I missing?

PS.: Both EntityOne and EntityTwo have a version attribute.


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.