Kjeld
Kjeld

Reputation: 470

OpenJPA Syntax error: Encountered "optimize"

When using OpenJPA to execute a select statement in in-memory database org.apache.derby, I encounter this error:

javax.ejb.EJBException: The bean encountered a non-application exception; nested exception is: 
<openjpa-2.1.2-SNAPSHOT-r422266:1636464 fatal general error> org.apache.openjpa.persistence.PersistenceException: Syntax error: Encountered "optimize" at line 1, column 80. {SELECT t0.VERSION, t0.SOMEOTHER_COLUMN FROM MYTABLE t0 WHERE t0.MYTABLE_CODE = ?  optimize for 1 row} [code=20000, state=42X01] FailedObject: UDA [org.apache.openjpa.util.StringId] [java.lang.String]

The OpenJPA client is embedded in a IBM WebSphere client: com.ibm.ws.jpa.thinclient-8.5.5.5.jar

Apparently OpenJPA adds the 'optimize for 1 row' part because it thinks it is dealing with DB2? How could this be possible? Is there any way I can turn off this feature explicitly?

I did find some explanation on the 'optimize for 1 row' postfix: https://www.ibm.com/developerworks/community/blogs/22586cb0-8817-4d2c-ae74-0ddcc2a409bc/entry/optimize_for_1_row1?lang=en

Upvotes: 1

Views: 265

Answers (2)

Kjeld
Kjeld

Reputation: 470

Solved it. The application has derby configured, but it is using a data access service which in turn had db2 specified as the DB dictionary. I am servicing on existing code and therefore could not find that setting right away. Thank you both for pointing me in the right direction.

Upvotes: 0

Andy Guibert
Andy Guibert

Reputation: 42966

Apparently OpenJPA adds the 'optimize for 1 row' part because it thinks it is dealing with DB2? How could this be possible? Is there any way I can turn off this feature explicitly?

With the information provided, I'm not sure why this is the case.

Fortunately, you can override this with the following property in your persistence.xml:

<property name="openjpa.jdbc.DBDictionary" value="derby"/>

Upvotes: 1

Related Questions