Search code examples
hibernatejpaopenjpa

Simple JPQL query not working in OpenJPA


The following query that is working perfectly fine when I am using hibernate as the JPA provider is not working with OpenJPA:

entityManager.createQuery(
        "select ord from Order ord " +
        "where symbol = :symbol")
    .setParameter("symbol", symbol)
    .getResultList();

The error returned is

java.lang.IllegalArgumentException: Invalid unbound variable "symbol" in query

Am I doing something wrong in my query that OpenJPA does not like?


Solution

  • I believe you want to change:"where symbol = :symbol" to :

     "where ord.symbol = :symbol"
    

    Or, use positional parameters:

    "where ord.symbol = ?1"
    
      .setParameter(1, symbol)
    

    Hope that helps.