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