1
在OpenJPA 2.1和oracle數據庫的項目中,我使用混合鎖模式,該模式默認具有樂觀鎖定,但也可以使用悲觀模式。但它不適合我,如我所料。 所以我寫了openjpa鎖定的小測試。Openjpa鎖不起作用
Persistance.xml配置:
<properties>
<property name="openjpa.Optimistic" value="false" />
<property name="openjpa.LockManager" value="mixed" />
<!-- <property name="openjpa.LockManager"value="mixed(VersionCheckOnReadLock=true,VersionUpdateOnWriteLock=true)" /> -->
<property name="openjpa.RuntimeUnenhancedClasses" value="unsupported" />
<property name="openjpa.slice.ConnectionDriverName" value="oracle.jdbc.OracleDriver" />
<property name="openjpa.slice.ConnectionURL" value="jdbc:oracle:thin:******" />
<property name="openjpa.slice.ConnectionUserName" value="user" />
<property name="openjpa.slice.ConnectionPassword" value="userpassword" />
<property name="openjpa.jdbc.SynchronizeMappings" value="validate" />
<property name="openjpa.jdbc.SchemaFactory" value="native(ForeignKeys=true)" />
<property name="openjpa.Log"
value="DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=TRACE" />
</properties>
我簡單的測試代碼:
Configuration config = entityManager.find(Configuration.class, 10025984L);
entityManager.lock(config, LockModeType.PESSIMISTIC_WRITE);
SQL跟蹤是看到的,後鎖的方法調用OpenJPA的不執行任何額外的查詢數據庫。單SQL查詢:
TRACE [Thread-7] openjpa.jdbc.SQL - <t 874198043, conn 1773300146> executing prepstmnt 1809148885 SELECT t0.VERSION FROM Configuration t0 WHERE t0.ID = ? [params=?]
我做錯了什麼,我怎麼能鎖定一個實體實例?