Hello all,
I'm using Hibernate 3.0 and have run into an issue. My application uses Oracle 8i on the backend. There is a part of my application that must use pessimistic locking. I've tried the following code:
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.getCurrentSession();
Transaction tx = session.beginTransaction();
Manager manager = (Manager)session.get(
Manager.class,
new Long(33), LockMode.UPGRADE);
LockMode lockMode = session.getCurrentLockMode(manager);
Integer status = manager.getStatus();
manager.setStatus(new Integer(status.intValue() + iAmount));
session.save(manager);
tx.commit();
sessionFactory.close();
And here is the SQL that hibernate generates and prints to the console:
15:20:48,151 INFO [STDOUT] Hibernate: select manager0_.id as id1_0_, manager0_.name as name1_0_, manager0_.status as status1_0_ from TESTEJB manager0_ where manager0_.id=?
I was expecting to see a " for update" appended to the end of the above - but it's not there. In addition, I'm able to modify the row in question from a different application that updates the DB. Is there something else I need to do to make this work? Is there something in my hibernate.cfg.xml or mapping files where I need to indicate that my DB is oracle? Or does hibernate just figure this out based on the driver that I'm using?
Here's my hibernate.cfg.xml file:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@XXX.XXX.XXX.com:1521:sds</property>
<property name="connection.username">XXX</property>
<property name="connection.password">XXX</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<!-- <property name="hbm2ddl.auto">create</property> -->
<mapping resource="data/Process.hbm.xml"/>
<mapping resource="data/Manager.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Any light you can shed would be appreciated!
-john
|