3

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...)

Community
  • 1
  • 1
Steven Schlansker
  • 37,580
  • 14
  • 81
  • 100

1 Answers1

2

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...

Steven Schlansker
  • 37,580
  • 14
  • 81
  • 100
  • 1
    I highly recommend NOT using that property. Please read http://openjpa.apache.org/entity-enhancement.html for more info. – Rick Nov 05 '10 at 17:17
  • @Rick: right now I'm just playing around and I really don't want to have to add a build step between every compile / run cycle... – Steven Schlansker Nov 05 '10 at 17:43
  • I'd suggest using the -javaagent.... If you're running in eclipse it's super easy to get going. – Rick Nov 05 '10 at 18:42
  • 1
    I tried that but it didn't seem to work. Didn't print out any messages at all (I have DEBUG level enabled), and it complained that the classes were not enhanced. – Steven Schlansker Nov 05 '10 at 21:16