The following code works well with MySQL.
But the same code fails when switching HSQLDB in-memory database (for unit test),
Query query = entityManager.createQuery("SELECT c FROM CartInvoiceEntity c WHERE c.invoiceId = :invoiceId");
query.setParameter("invoiceId", cartInvoiceEntity.getInvoiceId());
with the following error message:
org.hibernate.QueryParameterException: could not locate named parameter [invoiceId]
Inspected on query object when debugging, I found the query object has a parameters field. When using MySQL, this parameters contains "invoiceId" in its HashMap. But when switching to HSQLDB, this HashMap is empty -- this is why the exception thrown. The question is why the HashMap is empty with HSQLDB being used.
Following is the relevant Maven dependencies
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.9.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.1.9.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.16</version>
</dependency>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.10</version>
<scope>test</scope>
</dependency>
From the dependency hierarchy, I can see hibernate-jpa-2.0.api:1.0.1.Final is used and it is indirectly referenced from both hibernate-core and hibernate-entitymanager JARs.
Any help is highly appreciated!