Hi,
I seem to need some help understanding how record locking works in Derby
because I can't seem to make it work for me.
I have a single table with about 5,000 records. There is an Ocean field that
has one of two values: ATL or PAC. I want the users to be able to query the
table using the Ocean attribute and obtain a lock on all of the "ATL" records
from the time the select statement is issued until they end their editing
session and finally update the database. The lock could be need for several
hours.
I am using Derby in network server mode on my local machine. I am using JPA to
access the database. I am using Hibernate Persistence as my JPA provider. In
the persistence.xml file I set the following property:
<property name = "hibernate.dialect" value="org.hibernate.dialect.DerbyDialect"
/>
<property name = "hibernate.connection.isolation" value="4" />
When I start the session, it appears that a repeatable read connection is made
to the database.
There is an index created on the ocean field in the class using JPA with
hibernate extensions:
@Column(name = "OCEAN", nullable = "false");
@org.hibernate.annotations.Index(name = "ocean", columNames="OCEAN"))
I issue the following select statement to retrieve the records from the
database and hopefully obtain the lock:
Public ArrayList<FleetExchangeActivity> getActivities(Ocean ocean, boolean
isReadOnly){
Query q = this.getEntityManager().createQuery("select a from
FleetExchangeActivity a where a.ocean =
:ocean").setHint("org.hibernate.readOnly", isReadOnly);
q.setParameter("ocean", ocean);
return (ArrayList<FleetExchangeActivity>) q.getResultList();
}
I use the isReadOnly boolean to indicate whether the user wishes to view ( no
lock) or edit (lock please) the result set.
I am missing something here? When I run a test and query all the records with
ocean=ATL, then run the same query again, using the same EntityManager object
and the same ocean attribute, I am able to update the records returned by the
second query.
Any help you can provide will be greatly appreciated. Thanks, Dan
Dan Hawley
Lockheed-Martin Space Systems Company, Sunnyvale, CA
Business Application Programmer, Sr. Staff
Program Plans and Requirements O/B31S
B/181 Col 1A3
Office: (408) 742-3888