-->
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: Locking problem
PostPosted: Tue Apr 10, 2007 9:26 am 
Newbie

Joined: Thu Dec 23, 2004 7:23 am
Posts: 12
Location: Melbourne
Hi,

NOTE: This is actually the simplified version of a real-world problem I have faced in developing a Web app.

I have a simple persistent class named Language:

Code:
<hibernate-mapping>
    <class name="com.behrangsa.data.Language" table="language">
        <id name="id" column="id">
            <generator class="native" />
        </id>
        <property name="title" length="50" not-null="true"/>
    </class>
</hibernate-mapping>


Suppose that I want to save two instances of Language, one in the current session, the other one in another session:

Code:
SessionFactory factory = HibernatePractice.getSessionFactory();
Session currentSession = factory.getCurrentSession();
currentSession.beginTransaction();

Language lang1 = new Language();
lang1.setTitle("Language 1");
currentSession.save(lang1);

Session secondSession = factory.openSession();
secondSession.beginTransaction();
Language lang2 = new Language();
lang2.setTitle("Language 2");
secondSession.save(lang2);
secondSession.getTransaction().commit();

currentSession.getTransaction().commit();


Now when I try to execute the above code, I encounter the following exception:

Code:
Caused by: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2921)
...


As long as I know MySQL 4.1.x uses row level locking, so I though that this shouldn't be an issue. Any ideas what is the problem with the above code?

Thanks in advance,
Behrang

_________________
http://www.koderblogz.com


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.