-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate 3.0 not doing pessimistic locking with Oracle 8i
PostPosted: Thu Mar 16, 2006 7:21 pm 
Newbie

Joined: Thu Mar 16, 2006 1:12 pm
Posts: 10
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 17, 2006 6:36 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Check your dialect - HSQL does not support pessimistic locking..
Use the oracle dialect instead


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.