You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Fay Wang (JIRA)" <ji...@apache.org> on 2010/03/29 20:05:27 UTC
[jira] Created: (OPENJPA-1602) Query with lock mode set to
PESSIMISTIC_WRITE does not have for update clause attached to the sql when
runs twice
Query with lock mode set to PESSIMISTIC_WRITE does not have for update clause attached to the sql when runs twice
-----------------------------------------------------------------------------------------------------------------
Key: OPENJPA-1602
URL: https://issues.apache.org/jira/browse/OPENJPA-1602
Project: OpenJPA
Issue Type: Bug
Components: jdbc
Affects Versions: 2.1.0
Reporter: Fay Wang
The following test case executes query two times.
The sql generated for the first time:
sql = SELECT t0.KEYNAME, t0.KEYVAL FROM KEYGEN t0 WHERE (t0.KEYNAME = ?) optimize for 1 row FOR READ ONLY WITH RR USE AND KEEP UPDATE LOCKS
The sql generated for the second time:
sql = SELECT t0.KEYNAME, t0.KEYVAL FROM KEYGEN t0 WHERE (t0.KEYNAME = ?)
public void testKeyGen() {
EntityManager em = emf.createEntityManager();
KeyGenEntity key = null;
em.getTransaction().begin();
for (int i = 0;i < 2; i++) {
Query q = em.createNamedQuery("getStationKeyForUpdate");
q.setLockMode(LockModeType.PESSIMISTIC_WRITE);
q.setParameter("keyname", keyName);
try {
key = (KeyGenEntity) q.getSingleResult();
em.refresh(key);
}
catch (NoResultException e) {
// No keys found for this name - create a new one
int keyVal = 0;
key = new KeyGenEntity(keyName, keyVal);
em.persist(key);
em.lock(key, LockModeType.PESSIMISTIC_WRITE);
}
int keyVal = key.getKeyval();
key.setKeyval(keyVal + 1);
}
em.getTransaction().commit();
}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (OPENJPA-1602) Query with lock mode set to
PESSIMISTIC_WRITE does not have for update clause attached to the sql when
runs twice
Posted by "Donald Woods (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/OPENJPA-1602?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Donald Woods updated OPENJPA-1602:
----------------------------------
Priority: Critical (was: Major)
Affects Version/s: (was: 2.1.0)
2.0.0
Fix Version/s: 2.0.0
Assignee: Pinaki Poddar
showing as affects/fix for 2.0.0
> Query with lock mode set to PESSIMISTIC_WRITE does not have for update clause attached to the sql when runs twice
> -----------------------------------------------------------------------------------------------------------------
>
> Key: OPENJPA-1602
> URL: https://issues.apache.org/jira/browse/OPENJPA-1602
> Project: OpenJPA
> Issue Type: Bug
> Components: jdbc
> Affects Versions: 2.0.0
> Reporter: Fay Wang
> Assignee: Pinaki Poddar
> Priority: Critical
> Fix For: 2.0.0
>
>
> The following test case executes query two times.
> The sql generated for the first time:
> sql = SELECT t0.KEYNAME, t0.KEYVAL FROM KEYGEN t0 WHERE (t0.KEYNAME = ?) optimize for 1 row FOR READ ONLY WITH RR USE AND KEEP UPDATE LOCKS
> The sql generated for the second time:
> sql = SELECT t0.KEYNAME, t0.KEYVAL FROM KEYGEN t0 WHERE (t0.KEYNAME = ?)
> public void testKeyGen() {
> EntityManager em = emf.createEntityManager();
> KeyGenEntity key = null;
> em.getTransaction().begin();
> for (int i = 0;i < 2; i++) {
> Query q = em.createNamedQuery("getStationKeyForUpdate");
> q.setLockMode(LockModeType.PESSIMISTIC_WRITE);
> q.setParameter("keyname", keyName);
> try {
> key = (KeyGenEntity) q.getSingleResult();
> em.refresh(key);
> }
> catch (NoResultException e) {
> // No keys found for this name - create a new one
> int keyVal = 0;
> key = new KeyGenEntity(keyName, keyVal);
> em.persist(key);
> em.lock(key, LockModeType.PESSIMISTIC_WRITE);
> }
> int keyVal = key.getKeyval();
> key.setKeyval(keyVal + 1);
> }
> em.getTransaction().commit();
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Resolved: (OPENJPA-1602) Query with lock mode set to
PESSIMISTIC_WRITE does not have for update clause attached to the sql when
runs twice
Posted by "Donald Woods (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/OPENJPA-1602?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Donald Woods resolved OPENJPA-1602.
-----------------------------------
Resolution: Fixed
> Query with lock mode set to PESSIMISTIC_WRITE does not have for update clause attached to the sql when runs twice
> -----------------------------------------------------------------------------------------------------------------
>
> Key: OPENJPA-1602
> URL: https://issues.apache.org/jira/browse/OPENJPA-1602
> Project: OpenJPA
> Issue Type: Bug
> Components: jdbc
> Affects Versions: 2.0.0
> Reporter: Fay Wang
> Assignee: Pinaki Poddar
> Priority: Critical
> Fix For: 2.0.0
>
>
> The following test case executes query two times.
> The sql generated for the first time:
> sql = SELECT t0.KEYNAME, t0.KEYVAL FROM KEYGEN t0 WHERE (t0.KEYNAME = ?) optimize for 1 row FOR READ ONLY WITH RR USE AND KEEP UPDATE LOCKS
> The sql generated for the second time:
> sql = SELECT t0.KEYNAME, t0.KEYVAL FROM KEYGEN t0 WHERE (t0.KEYNAME = ?)
> public void testKeyGen() {
> EntityManager em = emf.createEntityManager();
> KeyGenEntity key = null;
> em.getTransaction().begin();
> for (int i = 0;i < 2; i++) {
> Query q = em.createNamedQuery("getStationKeyForUpdate");
> q.setLockMode(LockModeType.PESSIMISTIC_WRITE);
> q.setParameter("keyname", keyName);
> try {
> key = (KeyGenEntity) q.getSingleResult();
> em.refresh(key);
> }
> catch (NoResultException e) {
> // No keys found for this name - create a new one
> int keyVal = 0;
> key = new KeyGenEntity(keyName, keyVal);
> em.persist(key);
> em.lock(key, LockModeType.PESSIMISTIC_WRITE);
> }
> int keyVal = key.getKeyval();
> key.setKeyval(keyVal + 1);
> }
> em.getTransaction().commit();
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (OPENJPA-1602) Query with lock mode set to
PESSIMISTIC_WRITE does not have for update clause attached to the sql when
runs twice
Posted by "Fay Wang (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/OPENJPA-1602?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12851056#action_12851056 ]
Fay Wang commented on OPENJPA-1602:
-----------------------------------
The following is the KeyGenEntity.java:
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
/**
* Handles key gen generation for a number of cases.
*
*/
@Entity
@Table(name="KEYGEN")
@NamedQuery(name="getStationKeyForUpdate",
query="select kg from KeyGenEntity as kg where kg.keyname = :keyname")
public class KeyGenEntity {
@Id
@Column(name="KEYNAME")
private String keyname;
@Column(name="KEYVAL")
private int keyval;
public String getKeyname() {
return keyname;
}
public void setKeyname(String keyname) {
this.keyname = keyname;
}
public int getKeyval() {
return keyval;
}
public void setKeyval(int keyval) {
this.keyval = keyval;
}
public KeyGenEntity() {
}
public KeyGenEntity(String keyname, int keyval) {
super();
this.keyname = keyname;
this.keyval = keyval;
}
}
> Query with lock mode set to PESSIMISTIC_WRITE does not have for update clause attached to the sql when runs twice
> -----------------------------------------------------------------------------------------------------------------
>
> Key: OPENJPA-1602
> URL: https://issues.apache.org/jira/browse/OPENJPA-1602
> Project: OpenJPA
> Issue Type: Bug
> Components: jdbc
> Affects Versions: 2.1.0
> Reporter: Fay Wang
>
> The following test case executes query two times.
> The sql generated for the first time:
> sql = SELECT t0.KEYNAME, t0.KEYVAL FROM KEYGEN t0 WHERE (t0.KEYNAME = ?) optimize for 1 row FOR READ ONLY WITH RR USE AND KEEP UPDATE LOCKS
> The sql generated for the second time:
> sql = SELECT t0.KEYNAME, t0.KEYVAL FROM KEYGEN t0 WHERE (t0.KEYNAME = ?)
> public void testKeyGen() {
> EntityManager em = emf.createEntityManager();
> KeyGenEntity key = null;
> em.getTransaction().begin();
> for (int i = 0;i < 2; i++) {
> Query q = em.createNamedQuery("getStationKeyForUpdate");
> q.setLockMode(LockModeType.PESSIMISTIC_WRITE);
> q.setParameter("keyname", keyName);
> try {
> key = (KeyGenEntity) q.getSingleResult();
> em.refresh(key);
> }
> catch (NoResultException e) {
> // No keys found for this name - create a new one
> int keyVal = 0;
> key = new KeyGenEntity(keyName, keyVal);
> em.persist(key);
> em.lock(key, LockModeType.PESSIMISTIC_WRITE);
> }
> int keyVal = key.getKeyval();
> key.setKeyval(keyVal + 1);
> }
> em.getTransaction().commit();
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.