Question

I'm trying out OpenJPA 2.0.1 for the first time, and am getting:

79  WARN   [main] openjpa.Runtime - The configuration property named "openjpa.Id" was not recognized and will be ignored, although the name closely matches a valid property called "openjpa.Id".
179  INFO   [main] openjpa.Runtime - Starting OpenJPA 2.0.1
371  INFO   [main] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.PostgresDictionary" (PostgreSQL 8.4.4 ,PostgreSQL Native Driver PostgreSQL 9.0 JDBC4 (build 801)).
<openjpa-2.0.1-r422266:989424 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Attempt to cast instance "x.quality.QualityQuery@4c4b11e9" to PersistenceCapable failed.  Ensure that it has been enhanced.
FailedObject: x.quality.QualityQuery@4c4b11e9
    at org.apache.openjpa.kernel.BrokerImpl.assertPersistenceCapable(BrokerImpl.java:4559)
    at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2561)
    at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2423)
    at org.apache.openjpa.kernel.DelegatingBroker.persist(DelegatingBroker.java:1069)
    at org.apache.openjpa.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:706)
    at ...

According to the OpenJPA docs, I shouldn't have to do anything to get the basic enhancement at runtime:

2.5. Omitting the OpenJPA enhancer

OpenJPA does not require that the enhancer be run. If you do not run the enhancer, OpenJPA will fall back to one of several possible alternatives for state tracking, depending on the execution environment.

Java 6 class retransformation:

if you are running your application in a Java 6 environment, OpenJPA will attempt to dynamically register a ClassTransformer that will redefine your persistent classes on the fly to track access to persistent data. Additionally, OpenJPA will create a subclass for each of your persistent classes. When you execute a query or traverse a relation, OpenJPA will return an instance of the subclass. This means that the instanceof operator will work as expected, but o.getClass() will return the subclass instead of the class that you wrote. You do not need to do anything at all to get this behavior. OpenJPA will automatically detect whether or not the execution environment is capable of Java 6 class retransformation.

Any clues why this isn't working? Thanks much...

(Bonus points for why the openjpa.Id warning happens - I haven't set any such property...)

Was it helpful?

Solution

Aha, turns out that the answer was to pass in:

"openjpa.RuntimeUnenhancedClasses" => RuntimeUnenhancedClassesModes.SUPPORTED

to the configuration map. Why this is not documented more clearly, I'm not sure...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top