Topic
17 replies Latest Post - ‏2012-04-05T22:41:15Z by Veluri
earlRogers
earlRogers
26 Posts
ACCEPTED ANSWER

Pinned topic JPA Configuration

‏2009-07-01T14:30:20Z |
I've seen a couple threads indicating that it should be possible to use JPA implemetation of BDS. Has anyone gotten it to work? I have tried a simple test but can't resolve the exception below. Generally I've found that to indicate a missing persistence.xml file, but that shouldn't be the case here.

org.apache.openjpa.persistence.ArgumentException: An error occurred while parsing the query filter "SELECT new com.bac.zsa.sandbox.notes.jpa.CustomerId(c.customerId) FROM CustomerNotes c GROUP BY c.customerId ORDER BY c.customerId DESC". Error message: The name "CustomerNotes" is not a recognized entity or identifier. Known entity names: []
at org.apache.openjpa.kernel.exps.AbstractExpressionBuilder.parseException(AbstractExpressionBuilder.java:118)

Any suggestions?
Thanks,
Earl
Updated on 2012-04-05T22:41:15Z at 2012-04-05T22:41:15Z by Veluri
  • SystemAdmin
    SystemAdmin
    783 Posts
    ACCEPTED ANSWER

    Re: JPA Configuration

    ‏2009-07-01T18:44:31Z  in response to earlRogers
    Hey Earl,
    Have you tried running the SimpleJPASample that ships with the product? You should also find instructions on installing and configuring the sample. Let me know if you have trouble locating it.
    We currently only support OpenJPA that needs to be downloaded separately (and not the JPA implementation that comes up with EJB 3.0 fixpack).
    Thanks
    Neeraj
    • SystemAdmin
      SystemAdmin
      783 Posts
      ACCEPTED ANSWER

      Re: JPA Configuration

      ‏2009-07-01T19:07:03Z  in response to SystemAdmin
      Hey Earl,
      In case you have trouble locating the sample. It is located under <WAS_HOME>/installableApps/SimpleJPASample.ear
      Instructions can be found under <WAS_HOME>/longRunning/SimpleJPASampleREADME.txt
      I am assuming you have CG 6.1.0.5
      Thanks
      Neeraj
      Updated on 2009-07-01T19:07:03Z at 2009-07-01T19:07:03Z by SystemAdmin
      • earlRogers
        earlRogers
        26 Posts
        ACCEPTED ANSWER

        Re: JPA Configuration

        ‏2009-07-01T19:04:51Z  in response to SystemAdmin
        Thanks. I found the sample and have imported it into RAD. I didn't realize there was a JPA sample. I'll give it a try.
        • earlRogers
          earlRogers
          26 Posts
          ACCEPTED ANSWER

          Re: JPA Configuration

          ‏2009-07-02T11:36:34Z  in response to earlRogers
          Chris,
          It appears that the sample has the same issue I was seeing. I think the problem relates back to this warning:

          7/2/09 7:16:42:452 EDT 00000067 SystemErr R 9266 hellojpa WARN [java.lang.ThreadGroupname=DefaultWorkManager: SimpleJPASampleEAR,maxpri=10] openjpa.Enhance - This configuration disallows runtime optimization, but the following listed types were not enhanced at build time or at class load time with a javaagent: "http://class com.ibm.websphere.batch.samples.streams.Message".

          Is there a WAS setting I have missed in my JPA config?

          I have attached the full console log for the sample run.

          Regards,

          Earl
          • SystemAdmin
            SystemAdmin
            783 Posts
            ACCEPTED ANSWER

            Re: JPA Configuration

            ‏2009-07-06T17:08:32Z  in response to earlRogers
            Hi Earl,
            What version of WAS are you using? and what version of OpenJPA did you download and copy to the WAS_HOME/lib directory?
            Thanks
            Neeraj
            • earlRogers
              earlRogers
              26 Posts
              ACCEPTED ANSWER

              Re: JPA Configuration

              ‏2009-07-07T02:17:11Z  in response to SystemAdmin
              WAS 7.0 and OpenJPA 1.2.1. I was able to get around the issue with my POC by running wsenhancer (command line) against my entity class. I have not tried it with the sample, but I assume it would work for that as well.
              Regards,
              Earl
              • earlRogers
                earlRogers
                26 Posts
                ACCEPTED ANSWER

                Re: JPA Configuration

                ‏2009-07-13T13:26:31Z  in response to earlRogers
                I am using a non-XA datasource and getting an exception when the JPAWriter attempts to commit.

                org.apache.openjpa.persistence.RollbackException: DSRA9350E: Operation Connection.commit is not allowed during a global transaction.

                From what I have found in Google, my transaction should either be using Bean managed persistence or not be attempting to commit. Does anyone have a suggestion?
                Thanks,
                Earl
                • SystemAdmin
                  SystemAdmin
                  783 Posts
                  ACCEPTED ANSWER

                  Re: JPA Configuration

                  ‏2009-07-13T14:57:00Z  in response to earlRogers
                  Hi Earl,
                  A question about your sample, what is the difference between the one that you said worked earlier and this one? Can you share your persistence.xml? and any logs that you may have.
                  Thanks
                  Neeraj
                  • earlRogers
                    earlRogers
                    26 Posts
                    ACCEPTED ANSWER

                    Re: JPA Configuration

                    ‏2009-07-13T15:16:21Z  in response to SystemAdmin
                    The one that worked wasn't using the CG framework to access the JPA datasource. It was accessing the database using a JPAManager directly from the BatchJobStepInterface processJobStep() method as I was only using the database to get some seed values.

                    Persistence.xml attached. Not much to it. Actually exactly the same as in the other job.
                    • earlRogers
                      earlRogers
                      26 Posts
                      ACCEPTED ANSWER

                      Re: JPA Configuration

                      ‏2009-07-13T15:54:28Z  in response to earlRogers
                      Attached console log.
                      • earlRogers
                        earlRogers
                        26 Posts
                        ACCEPTED ANSWER

                        Re: JPA Configuration

                        ‏2009-07-13T15:56:00Z  in response to earlRogers
                        Attached JPAWriter updated with JPAManager annotations.
                        • earlRogers
                          earlRogers
                          26 Posts
                          ACCEPTED ANSWER

                          Re: JPA Configuration

                          ‏2009-07-14T13:24:08Z  in response to earlRogers
                          A quick update... I have no issues using the same datasource with similar coding techniques as an input stream. See the attached zip file for the JPAInputStream and JPAReader source.
                          • SystemAdmin
                            SystemAdmin
                            783 Posts
                            ACCEPTED ANSWER

                            Re: JPA Configuration

                            ‏2009-07-15T20:25:22Z  in response to earlRogers
                            Hi Earl,
                            Is it possible to share your sample application ? Might be easier for us to debug and figure out whats going wrong.
                            If you prefer you can send us your application via email through your IBM representative.
                            Thanks
                            Neeraj
                            • earlRogers
                              earlRogers
                              26 Posts
                              ACCEPTED ANSWER

                              Re: JPA Configuration

                              ‏2009-07-16T03:33:07Z  in response to SystemAdmin
                              I have renamed some classes and packages since earlier postings. Here is the most current application and the console log with the error.

                              File index
                              Console log: console.log.txt
                              Streams: JPAOutputStream.java, JPAWriter (SandboxNotesJPA.jar), TextFileStream.java
                              Step: CreateCustomerNotes.java
                              Props: CreateCustomerNotes.props
                              Entity: CustomerNotes (SandboxNotesJPA.jar)

                              As noted in earlier posts, its necessary to manually enhance the entity class using %app_server_root%\bin\wsenhancer.bat prior to packaging the application.

                              Another interesting problem I've encountered is that classes in utility jar files in lib (path ../lib from the ant script) are not found. That's why you see SandboxNotesJPA.jar in the ear root.

                              Here's the xJCL for reference:
                              <job name="CreateCustomerNotes" default-application-name="CreateCustomerNotes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                              <jndi-name>ejb/com/ibm/ws/batch/CreateCustomerNotesBatchController</jndi-name>
                              <step-scheduling-criteria>
                              <scheduling-mode>sequential</scheduling-mode>
                              </step-scheduling-criteria>
                              <checkpoint-algorithm name="chkpt">
                              <classname>com.bac.zsa.sandbox.notes.batch.spi.SandboxNotesRecordbased</classname>
                              <props>
                              <prop name="recordcount" value="5"/>
                              </props>
                              </checkpoint-algorithm>
                              <results-algorithms>
                              <results-algorithm name="jobsum">
                              <classname>com.ibm.wsspi.batch.resultsalgorithms.jobsum</classname>
                              </results-algorithm>
                              </results-algorithms>
                              <job-step name="Step1">
                              <jndi-name>ejb/com/bac/zsa/sandbox/notes/batch/CreateCustomerNotes</jndi-name>
                              <checkpoint-algorithm-ref name="chkpt"/>
                              <results-ref name="jobsum"/>
                              <batch-data-streams>
                              <bds>
                              <logical-name>outputStream</logical-name>
                              <props>
                              <prop name="EnablePerformanceMeasurement" value="false"/>
                              <prop name="EnableDetailedPerformanceMeasurement" value="false"/>
                              <prop name="PERSISTENT_UNIT" value="SandboxNotesJPA"/>
                              <prop name="debug" value="true"/>
                              <prop name="PATTERN_IMPL_CLASS" value="com.bac.zsa.sandbox.notes.batch.streams.JPAOutputStream"/>
                              </props>
                              <impl-class>com.bac.zsa.sandbox.notes.jpa.controller.JPAWriter</impl-class>
                              </bds>
                              <bds>
                              <logical-name>inputStream</logical-name>
                              <props>
                              <prop name="FILENAME" value="C:/Docume~1/ts03412/MyDocu~1/IBM/rationalsdp/workspace/SandboxNotesBatch/data/seed.txt"/>
                              <prop name="EnablePerformanceMeasurement" value="false"/>
                              <prop name="EnableDetailedPerformanceMeasurement" value="false"/>
                              <prop name="debug" value="true"/>
                              <prop name="PATTERN_IMPL_CLASS" value="com.bac.zsa.sandbox.notes.batch.streams.TextFileStream"/>
                              </props>
                              <impl-class>com.ibm.websphere.batch.devframework.datastreams.patterns.TextFileReader</impl-class>
                              </bds>
                              </batch-data-streams>
                              <props>
                              <prop name="EnablePerformanceMeasurement" value="false"/>
                              <prop name="EnableDetailedPerformanceMeasurement" value="false"/>
                              <prop name="debug" value="true"/>
                              <prop name="JobStepId" value="Seed"/>
                              <prop name="BATCHRECORDPROCESSOR" value="com.bac.zsa.sandbox.notes.batch.steps.CreateCustomerNotes"/>
                              <prop name="title" value="Seed Customer Notes Database"/>
                              </props>
                              </job-step>
                              </job>

                              Thanks,

                              Earl
                              • SystemAdmin
                                SystemAdmin
                                783 Posts
                                ACCEPTED ANSWER

                                Re: JPA Configuration

                                ‏2009-07-16T22:14:21Z  in response to earlRogers
                                Hi Earl,
                                So a couple of things:
                                1. Take a look at the persistence.xml below there are a few key things to note here:
                                
                                <persistence xmlns=
                                "http://java.sun.com/xml/ns/persistence" xmlns:xsi=
                                "http://www.w3.org/2001/XMLSchema-instance" version=
                                "1.0"> <persistence-unit name=
                                "hellojpa" transaction-type=
                                "RESOURCE_LOCAL">   <provider>com.ibm.websphere.persistence.PersistenceProviderImpl</provider> <non-jta-data-source>jdbc/simpleJPA</non-jta-data-source> <mapping-file>META-INF/orm.xml</mapping-file> <class>com.ibm.websphere.samples.Message</class> <properties> <property name=
                                "openjpa.jdbc.SynchronizeMappings" value=
                                "buildSchema" /> <property name=
                                "openjpa.jdbc.DBDictionary" value=
                                "db2"/> <property name=
                                "openjpa.RuntimeUnenhancedClasses" value=
                                "supported"/> <property name=
                                "openjpa.MetaDataFactory" value=
                                "jpa(Types=com.ibm.websphere.samples.Message)"/> </properties> </persistence-unit> </persistence>
                                

                                a. The transaction type is set to RESOURCE_LOCAL This is because we manage our own transactions instead of enlisting in the existing JTA transactions.

                                b. Use the tag non-jta-data-source instead. As we do not want this datasource to get enlisted in the global transaction.

                                c. You need to use a XA datasource (since you were using a non-xa datasource the commits were failing).

                                d. You need to set the custom property nonTransactionalDataSource=true on the above datasource. Note the ability to exclude a xa datasource from a global transaction is not available in older WAS versions (but is available in WAS 70).

                                e. If you do not want to enhance your persistent classes at build time set the RuntimeUnenhancedClasses to supported and list your class name in the MetaDataFactory property as in the above example. You could also pass them via your xJCL

                                f. WAS 7 comes with the EJB 3 feature pack so you don't have to download OpenJPA separately you can just set the provider to
                                com.ibm.websphere.persistence.PersistenceProviderImpl as above.

                                I am attaching an updated sample. You will need to create a DB2 XA datasource called jdbc/simpleJPA as described in c and d above and point it to a valid DB2 database.

                                Let us know if you have questions/issues.
                                Thanks
                                Neeraj
                                • earlRogers
                                  earlRogers
                                  26 Posts
                                  ACCEPTED ANSWER

                                  Re: JPA Configuration

                                  ‏2009-07-21T13:22:55Z  in response to SystemAdmin
                                  Thanks, Neeraj! My batch application is now working. I have one final step to build in order to complete our initial test.
                                  • Veluri
                                    Veluri
                                    31 Posts
                                    ACCEPTED ANSWER

                                    Re: JPA Configuration

                                    ‏2012-04-05T22:41:15Z  in response to earlRogers
                                    Thanks Neeraj: You Batch Application Solutions are very useful to me.
                                    I have question:
                                    question: In RSA 8 I created new Batch project. It creates EJB ,Batch and Enterprise Project.
                                    where Should I create my JPA entity class(es) file in EJB or Batch ..?