You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Albert Lee (JIRA)" <ji...@apache.org> on 2009/11/11 16:55:39 UTC

[jira] Created: (OPENJPA-1381) IllegalStateException on query method call after named query is created twice.

IllegalStateException on query method call after named query is created twice.
------------------------------------------------------------------------------

                 Key: OPENJPA-1381
                 URL: https://issues.apache.org/jira/browse/OPENJPA-1381
             Project: OpenJPA
          Issue Type: Bug
          Components: kernel
    Affects Versions: 2.0.0
            Reporter: Albert Lee
            Assignee: Albert Lee
             Fix For: 2.0.0


When a query method is called (e.g. setLockMode) on a named query that has been created twice, an IllegalStateException is thrown:

  Query q1 = em.createNamedQuery("xxxx");
  ,,,,
  Query q2 = em.createNamedQuery("xxxx");
  q2.setLockMode(READ);


11078  test  TRACE  [Thread-4] Tests - Caught exception and continue: java.lang.IllegalStateException: Query is neither a JPQL SELECT nor a Criteria API query.
11078  test  TRACE  [Thread-4] DumpStack - java.lang.IllegalStateException: Query is neither a JPQL SELECT nor a Criteria API query.
	at org.apache.openjpa.persistence.QueryImpl.assertJPQLOrCriteriaQuery(QueryImpl.java:377)
	at org.apache.openjpa.persistence.QueryImpl.setLockMode(QueryImpl.java:396)
	at org.apache.openjpa.persistence.QueryImpl.setLockMode(QueryImpl.java:1)
	at org.apache.openjpa.persistence.lockmgr.SequencedActionsTest.launchCommonSequence(SequencedActionsTest.java:409)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Reopened: (OPENJPA-1381) IllegalStateException on query method call after named query is created twice.

Posted by "Albert Lee (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1381?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Albert Lee reopened OPENJPA-1381:
---------------------------------


Pinaki,

The fix works for setLockMode() but still need implementation to protect getLockMode(). See my previous comment.

Thanks for getting this in so quickly.
Albert Lee. 

> IllegalStateException on query method call after named query is created twice.
> ------------------------------------------------------------------------------
>
>                 Key: OPENJPA-1381
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1381
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 2.0.0
>            Reporter: Albert Lee
>            Assignee: Pinaki Poddar
>             Fix For: 2.0.0-M4
>
>
> When a query method is called (e.g. setLockMode) on a named query that has been created twice, an IllegalStateException is thrown:
>   Query q1 = em.createNamedQuery("xxxx");
>   ,,,,
>   Query q2 = em.createNamedQuery("xxxx");
>   q2.setLockMode(READ);
> 11078  test  TRACE  [Thread-4] Tests - Caught exception and continue: java.lang.IllegalStateException: Query is neither a JPQL SELECT nor a Criteria API query.
> 11078  test  TRACE  [Thread-4] DumpStack - java.lang.IllegalStateException: Query is neither a JPQL SELECT nor a Criteria API query.
> 	at org.apache.openjpa.persistence.QueryImpl.assertJPQLOrCriteriaQuery(QueryImpl.java:377)
> 	at org.apache.openjpa.persistence.QueryImpl.setLockMode(QueryImpl.java:396)
> 	at org.apache.openjpa.persistence.QueryImpl.setLockMode(QueryImpl.java:1)
> 	at org.apache.openjpa.persistence.lockmgr.SequencedActionsTest.launchCommonSequence(SequencedActionsTest.java:409)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-1381) IllegalStateException on query method call after named query is created twice.

Posted by "Donald Woods (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1381?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Donald Woods updated OPENJPA-1381:
----------------------------------

    Fix Version/s:     (was: 2.0.0-M4)
                   2.0.0

> IllegalStateException on query method call after named query is created twice.
> ------------------------------------------------------------------------------
>
>                 Key: OPENJPA-1381
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1381
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 2.0.0
>            Reporter: Albert Lee
>            Assignee: Pinaki Poddar
>             Fix For: 2.0.0
>
>
> When a query method is called (e.g. setLockMode) on a named query that has been created twice, an IllegalStateException is thrown:
>   Query q1 = em.createNamedQuery("xxxx");
>   ,,,,
>   Query q2 = em.createNamedQuery("xxxx");
>   q2.setLockMode(READ);
> 11078  test  TRACE  [Thread-4] Tests - Caught exception and continue: java.lang.IllegalStateException: Query is neither a JPQL SELECT nor a Criteria API query.
> 11078  test  TRACE  [Thread-4] DumpStack - java.lang.IllegalStateException: Query is neither a JPQL SELECT nor a Criteria API query.
> 	at org.apache.openjpa.persistence.QueryImpl.assertJPQLOrCriteriaQuery(QueryImpl.java:377)
> 	at org.apache.openjpa.persistence.QueryImpl.setLockMode(QueryImpl.java:396)
> 	at org.apache.openjpa.persistence.QueryImpl.setLockMode(QueryImpl.java:1)
> 	at org.apache.openjpa.persistence.lockmgr.SequencedActionsTest.launchCommonSequence(SequencedActionsTest.java:409)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1381) IllegalStateException on query method call after named query is created twice.

Posted by "Albert Lee (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1381?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12776486#action_12776486 ] 

Albert Lee commented on OPENJPA-1381:
-------------------------------------

The problem is in PreparedQueryImpl, in which getLanauge() always return QueryLanguages.LANG_PREPARED_SQL regardless of the source of the cached Query. It is not sensitive to the query source.

In EntityManagerImpl.createNamedQuery:

    public OpenJPAQuery createNamedQuery(String name) {
        try {
            ....
            PreparedQuery pq = JPQLParser.LANG_JPQL.equals(meta.getLanguage())
                ? getPreparedQuery(qid) : null;
            org.apache.openjpa.kernel.Query del = (pq == null)
                ? _broker.newQuery(meta.getLanguage(), meta.getQueryString())
                : _broker.newQuery(pq.getLanguage(), pq);
            
The first time the named query is created, there is no query cached, a new Query is created using the metadata's language attribute (i.e. JPQL). The second time the named query is created, it is found in query cache, and the preparedQuery's language is used, which is ALWAYS SQL, that caused the ISEx when tested in the setLockMode() call path.



> IllegalStateException on query method call after named query is created twice.
> ------------------------------------------------------------------------------
>
>                 Key: OPENJPA-1381
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1381
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 2.0.0
>            Reporter: Albert Lee
>            Assignee: Albert Lee
>             Fix For: 2.0.0
>
>
> When a query method is called (e.g. setLockMode) on a named query that has been created twice, an IllegalStateException is thrown:
>   Query q1 = em.createNamedQuery("xxxx");
>   ,,,,
>   Query q2 = em.createNamedQuery("xxxx");
>   q2.setLockMode(READ);
> 11078  test  TRACE  [Thread-4] Tests - Caught exception and continue: java.lang.IllegalStateException: Query is neither a JPQL SELECT nor a Criteria API query.
> 11078  test  TRACE  [Thread-4] DumpStack - java.lang.IllegalStateException: Query is neither a JPQL SELECT nor a Criteria API query.
> 	at org.apache.openjpa.persistence.QueryImpl.assertJPQLOrCriteriaQuery(QueryImpl.java:377)
> 	at org.apache.openjpa.persistence.QueryImpl.setLockMode(QueryImpl.java:396)
> 	at org.apache.openjpa.persistence.QueryImpl.setLockMode(QueryImpl.java:1)
> 	at org.apache.openjpa.persistence.lockmgr.SequencedActionsTest.launchCommonSequence(SequencedActionsTest.java:409)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (OPENJPA-1381) IllegalStateException on query method call after named query is created twice.

Posted by "Albert Lee (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1381?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Albert Lee reassigned OPENJPA-1381:
-----------------------------------

    Assignee: Pinaki Poddar  (was: Albert Lee)

> IllegalStateException on query method call after named query is created twice.
> ------------------------------------------------------------------------------
>
>                 Key: OPENJPA-1381
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1381
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 2.0.0
>            Reporter: Albert Lee
>            Assignee: Pinaki Poddar
>             Fix For: 2.0.0
>
>
> When a query method is called (e.g. setLockMode) on a named query that has been created twice, an IllegalStateException is thrown:
>   Query q1 = em.createNamedQuery("xxxx");
>   ,,,,
>   Query q2 = em.createNamedQuery("xxxx");
>   q2.setLockMode(READ);
> 11078  test  TRACE  [Thread-4] Tests - Caught exception and continue: java.lang.IllegalStateException: Query is neither a JPQL SELECT nor a Criteria API query.
> 11078  test  TRACE  [Thread-4] DumpStack - java.lang.IllegalStateException: Query is neither a JPQL SELECT nor a Criteria API query.
> 	at org.apache.openjpa.persistence.QueryImpl.assertJPQLOrCriteriaQuery(QueryImpl.java:377)
> 	at org.apache.openjpa.persistence.QueryImpl.setLockMode(QueryImpl.java:396)
> 	at org.apache.openjpa.persistence.QueryImpl.setLockMode(QueryImpl.java:1)
> 	at org.apache.openjpa.persistence.lockmgr.SequencedActionsTest.launchCommonSequence(SequencedActionsTest.java:409)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1381) IllegalStateException on query method call after named query is created twice.

Posted by "Albert Lee (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1381?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12776851#action_12776851 ] 

Albert Lee commented on OPENJPA-1381:
-------------------------------------

The IllegalStateException semantics also apply to the Query.getLockMode() method call, per spec.  Similar usage of the ignorePreparedQuery() can be applied to getLockMode(), however it will lose the effectiveness of the cache (i.e. invalidate and rebuild) since getLockMode does not change the query's structure.


> IllegalStateException on query method call after named query is created twice.
> ------------------------------------------------------------------------------
>
>                 Key: OPENJPA-1381
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1381
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 2.0.0
>            Reporter: Albert Lee
>            Assignee: Albert Lee
>             Fix For: 2.0.0
>
>
> When a query method is called (e.g. setLockMode) on a named query that has been created twice, an IllegalStateException is thrown:
>   Query q1 = em.createNamedQuery("xxxx");
>   ,,,,
>   Query q2 = em.createNamedQuery("xxxx");
>   q2.setLockMode(READ);
> 11078  test  TRACE  [Thread-4] Tests - Caught exception and continue: java.lang.IllegalStateException: Query is neither a JPQL SELECT nor a Criteria API query.
> 11078  test  TRACE  [Thread-4] DumpStack - java.lang.IllegalStateException: Query is neither a JPQL SELECT nor a Criteria API query.
> 	at org.apache.openjpa.persistence.QueryImpl.assertJPQLOrCriteriaQuery(QueryImpl.java:377)
> 	at org.apache.openjpa.persistence.QueryImpl.setLockMode(QueryImpl.java:396)
> 	at org.apache.openjpa.persistence.QueryImpl.setLockMode(QueryImpl.java:1)
> 	at org.apache.openjpa.persistence.lockmgr.SequencedActionsTest.launchCommonSequence(SequencedActionsTest.java:409)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1381) IllegalStateException on query method call after named query is created twice.

Posted by "Albert Lee (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1381?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12776536#action_12776536 ] 

Albert Lee commented on OPENJPA-1381:
-------------------------------------

Work around of this limitation is to specify query hint "openjpa.hint.IgnorePreparedQuery" to true.

What is the reason cached query is treated as SQL and subsequently does not allow query methods that requires JPQL/Criteria API as the source language?

> IllegalStateException on query method call after named query is created twice.
> ------------------------------------------------------------------------------
>
>                 Key: OPENJPA-1381
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1381
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 2.0.0
>            Reporter: Albert Lee
>            Assignee: Albert Lee
>             Fix For: 2.0.0
>
>
> When a query method is called (e.g. setLockMode) on a named query that has been created twice, an IllegalStateException is thrown:
>   Query q1 = em.createNamedQuery("xxxx");
>   ,,,,
>   Query q2 = em.createNamedQuery("xxxx");
>   q2.setLockMode(READ);
> 11078  test  TRACE  [Thread-4] Tests - Caught exception and continue: java.lang.IllegalStateException: Query is neither a JPQL SELECT nor a Criteria API query.
> 11078  test  TRACE  [Thread-4] DumpStack - java.lang.IllegalStateException: Query is neither a JPQL SELECT nor a Criteria API query.
> 	at org.apache.openjpa.persistence.QueryImpl.assertJPQLOrCriteriaQuery(QueryImpl.java:377)
> 	at org.apache.openjpa.persistence.QueryImpl.setLockMode(QueryImpl.java:396)
> 	at org.apache.openjpa.persistence.QueryImpl.setLockMode(QueryImpl.java:1)
> 	at org.apache.openjpa.persistence.lockmgr.SequencedActionsTest.launchCommonSequence(SequencedActionsTest.java:409)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1381) IllegalStateException on query method call after named query is created twice.

Posted by "Albert Lee (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1381?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12776626#action_12776626 ] 

Albert Lee commented on OPENJPA-1381:
-------------------------------------

The limitation/requirement of using the query cache is documented in the manual.

The query cache is enabled by default, which is a problem for a JPA compliance application that has the reported usage pattern.

Pinaki agrees using this JIRA to either:
- make the Query cache disabled by default.
- invalidate the cache at the appropriate call path
- potentially using QueryImpl.ignorePreparedQuery() to automatically by-pass the problem.

Albert Lee.

> IllegalStateException on query method call after named query is created twice.
> ------------------------------------------------------------------------------
>
>                 Key: OPENJPA-1381
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1381
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 2.0.0
>            Reporter: Albert Lee
>            Assignee: Albert Lee
>             Fix For: 2.0.0
>
>
> When a query method is called (e.g. setLockMode) on a named query that has been created twice, an IllegalStateException is thrown:
>   Query q1 = em.createNamedQuery("xxxx");
>   ,,,,
>   Query q2 = em.createNamedQuery("xxxx");
>   q2.setLockMode(READ);
> 11078  test  TRACE  [Thread-4] Tests - Caught exception and continue: java.lang.IllegalStateException: Query is neither a JPQL SELECT nor a Criteria API query.
> 11078  test  TRACE  [Thread-4] DumpStack - java.lang.IllegalStateException: Query is neither a JPQL SELECT nor a Criteria API query.
> 	at org.apache.openjpa.persistence.QueryImpl.assertJPQLOrCriteriaQuery(QueryImpl.java:377)
> 	at org.apache.openjpa.persistence.QueryImpl.setLockMode(QueryImpl.java:396)
> 	at org.apache.openjpa.persistence.QueryImpl.setLockMode(QueryImpl.java:1)
> 	at org.apache.openjpa.persistence.lockmgr.SequencedActionsTest.launchCommonSequence(SequencedActionsTest.java:409)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (OPENJPA-1381) IllegalStateException on query method call after named query is created twice.

Posted by "Pinaki Poddar (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1381?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Pinaki Poddar resolved OPENJPA-1381.
------------------------------------

       Resolution: Fixed
    Fix Version/s:     (was: 2.0.0)
                   2.0.0-M4

Albert, see if this works. Otherwise I will reopen.

> IllegalStateException on query method call after named query is created twice.
> ------------------------------------------------------------------------------
>
>                 Key: OPENJPA-1381
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1381
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 2.0.0
>            Reporter: Albert Lee
>            Assignee: Pinaki Poddar
>             Fix For: 2.0.0-M4
>
>
> When a query method is called (e.g. setLockMode) on a named query that has been created twice, an IllegalStateException is thrown:
>   Query q1 = em.createNamedQuery("xxxx");
>   ,,,,
>   Query q2 = em.createNamedQuery("xxxx");
>   q2.setLockMode(READ);
> 11078  test  TRACE  [Thread-4] Tests - Caught exception and continue: java.lang.IllegalStateException: Query is neither a JPQL SELECT nor a Criteria API query.
> 11078  test  TRACE  [Thread-4] DumpStack - java.lang.IllegalStateException: Query is neither a JPQL SELECT nor a Criteria API query.
> 	at org.apache.openjpa.persistence.QueryImpl.assertJPQLOrCriteriaQuery(QueryImpl.java:377)
> 	at org.apache.openjpa.persistence.QueryImpl.setLockMode(QueryImpl.java:396)
> 	at org.apache.openjpa.persistence.QueryImpl.setLockMode(QueryImpl.java:1)
> 	at org.apache.openjpa.persistence.lockmgr.SequencedActionsTest.launchCommonSequence(SequencedActionsTest.java:409)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.