Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 331569

Summary: JPA 2: Reverify JPA 2.0 XSD support in persistence.xml on AM/CM app on WebLogic 10.3.3.0
Product: z_Archived Reporter: Michael OBrien <michael.f.obrien>
Component: EclipselinkAssignee: Michael OBrien <michael.f.obrien>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eclipselink.orm-inbox, sri.sankaran
Version: unspecifiedFlags: michael.f.obrien: documentation+
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
URL: http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/weblogic#Results_Matrix
Whiteboard:
Bug Depends on: 308477, 296271    
Bug Blocks: 334468    
Attachments:
Description Flags
Application managed SE PU EAR (needs eclipselink.jar put back in) runs JPA 2.0 code and JPA 2.0 XSD schema
none
Application managed SE PU EAR and WAR Eclipse project source (needs eclipselink.jar put back in) runs JPA 2.0 code and JPA 2.0 XSD schema none

Description Michael OBrien CLA 2010-12-01 12:08:47 EST
>Reverify row 1 on the support table for an application managed JPA 2.0 app with 2.0 version on the schema header

In response to 
http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg05619.html

1) verify that we can use the JPA 2.0 schema (on top of using JPA 2.0 at runtime)
- runtime JPA 2.0 api works
http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/weblogic#Output_1.3
  with the 1.0 schema no problem

- does this work?
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

>update the JPA 2.0 page and/or suggest a workaround to

A)
Caused By: weblogic.deployment.EnvironmentException: Error loading the persistence descriptor META-INF/persistence.xml from the module org.eclipse.persistence.example.jpa.dataparallel.serviceEJB.jar.  See the following stack trace for nested errors: weblogic.descriptor.DescriptorException: VALIDATION PROBLEMS WERE FOUND
  C:\wse\wls10330\org.eclipse.persistence.example.jpa.dataparallel.serviceEJB\build\classes\META-INF\persistence.xml:2:3:2:3: problem: cvc-attribute.4: The value '2.0' does not equal the fixed value '1.0' of attribute 'version':<C:\wse\wls10330\org.eclipse.persistence.example.jpa.dataparallel.serviceEJB\build\classes/META-INF/persistence.xml:2:3>

and/or a CCE on the implementation and spec PU as
Comment 1 Michael OBrien CLA 2010-12-01 12:23:28 EST
>The JPA 2.0 schema version work is part of comment 22 on bug # 296271
- debug how the proxy handles 2.0 functions through a container managed app
using the weblogic server source passed to us
- review detailed weaving support in container and application managed cases
- verify JPA 2.0 tags in persistence.xml using 2.0 XSD like
<shared-cache-mode>NONE</shared-cache-mode>

https://bugs.eclipse.org/bugs/show_bug.cgi?id=296271#c22
Comment 2 Michael OBrien CLA 2010-12-01 12:25:50 EST
>container managed apps and the 2.0 schema
https://bugs.eclipse.org/bugs/attachment.cgi?id=156842
20100121:
"Two issues surrounding the 2.0 spec jar is
    1) the inability to deploy container managed JPA 2 applications that define the 2.0 header in persistence xml - we need to raise a weblogic bug for this.
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
fails with the XSD 2.0 validation and later on a actual 2.0 element."
Comment 3 Michael OBrien CLA 2010-12-02 10:04:11 EST
>references
29 Mar 2010 - http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg04375.html
Me: "Note: that the 2.0 schema version for persistence.xml cannot be used 
in this specific case - stick to the 1.0 schema and tags.  All 2.0 API 
outside of actually defining these persistence.xml tags works fine using 
EclipseLink 2.0 however."

>unofficial 10.3.x discussion
http://netbeans.org/bugzilla/show_bug.cgi?id=189205
Comment 4 Michael OBrien CLA 2010-12-07 12:45:07 EST
>Update: There are 3 (possibly 4) issues here (all of these may become obsolete when the next WLS version ships)
Initially I got the 2.0 schema error and the ClassCastException on org.eclipse.persistence.jpa.PersistenceProvider
It turns out that my import of the 2 eclipse projects from my bug # 296271 for WebLogic 10.3.2.0 lost their facets(specifically the dynamic web facet) because I associated them with a different WebLogic 10.3.3.0. - this caused the CCE I was experiencing like Sri.
Anyways, after creating an EAR/Web project combination from scratch in eclipse associated with the 10.3.3.0 instance - I predeployed/deployed/ran fine - even with the 2.0 schema - in SE bootstrap mode (no EE yet). 

1) JPA 2.0 XSD usage on 10.3.3.0
- I reproduced this issue with a bad EAR
- was able to use the 2.0 schema within the WAR-only application managed EAR
>persistence.xml
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<!-- persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"-->
    <persistence-unit name="example2" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>localJTA</jta-data-source>
        <class>org.eclipse.persistence.example.business.Cell</class>
        <shared-cache-mode>NONE</shared-cache-mode>
        <properties>
            <property name="eclipselink.target-server" value="WebLogic_10"/>
            <property name="eclipselink.logging.level" value="FINEST"/>
            <property name="eclipselink.target-database" value="Derby"/>
            <!-- new for 10.3.3.0 http://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging#Server_Logging  -->
            <property name="eclipselink.logging.logger" value="DefaultLogger"/>
            <!-- property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>                        
            <property name="javax.persistence.jdbc.url" value="jdbc:derby://127.0.0.1:1527/dataparallel;create=true"/>
            <property name="javax.persistence.jdbc.user" value="APP"/>
            <property name="javax.persistence.jdbc.password" value="APP"/-->            
            <!-- turn off DDL generation after the model is stable -->            
            <!-- property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
            <property name="eclipselink.ddl-generation.output-mode" value="both"/-->
        </properties>       
    </persistence-unit>
</persistence>

2) CCE on JPA provider implementation class
Error instantiating the Persistence Provider class org.eclipse.persistence.jpa.PersistenceProvider of the PersistenceUnit example2: java.lang.ClassCastException: org.eclipse.persistence.jpa.PersistenceProvider
- I reproduced and fixed this one (was Eclipse project facet issue) - EAR was wrong
- was able to run JPA 2.0 code fine on an SE PU (predeploy/deploy together)
- EE injection should not work but I will post an example EAR anyway

>log
[EL Example]: enterprise: JPA 2.0 Metamodel: MetamodelImpl@56287508 [ 3 Types: , 1 ManagedTypes: , 1 EntityTypes: , 0 MappedSuperclassTypes: , 0 EmbeddableTypes: ]

3) CCE on JPA spec interface class
- I could not reproduce this one
http://forums.oracle.com/forums/thread.jspa?messageID=3946206&#3946206
Error processing persistence unit PT of module pt: Error instantiating the Persistence Provider class org.eclipse.persistence.jpa.PersistenceProvider of the PersistenceUnit PT: java.lang.ClassCastException: org.eclipse.persistence.jpa.PersistenceProvider cannot be cast to javax.persistence.spi.PersistenceProvider

4) CCE on fallback Kodo JPA provider (if an invalid say 2.1 JPA XSD schema is referenced)
java.lang.ClassCastException: kodo.persistence.PersistenceProviderImpl
	at javax.persistence.Persistence.findAllProviders(Persistence.java:186)

java.lang.NoSuchMethodError: javax/persistence/EntityManager.getMetamodel()Ljavax/persistence/metamodel/Metamodel;

- reproduced by using the 1.0 javax.persistence jar (but named as the 2.0 one in APP-INF/lib)
- fixed by using either the 1.0 or 2.0 JPA XSD schema and using the correct 2.0 spec jar

>Reproduction Procedure:
>redoing project from scratch as I noticed that the war was not at the root of the ear - it was a jar in the app-inf/lib dir - my imported eclipse project was not referenced correctly as a web module facet
- create empty EAR and WAR project with references
- download and open my EAR and WAR project code from bug # 296271
https://bugs.eclipse.org/bugs/show_bug.cgi?id=296271
- do essentially all the steps in the page below (I paraphrase for re-verification)
http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/weblogic#DI_1.1:_Alternative_3:_Application_Level_Shared_Library_-_In_Use
- copy applicationService, entity and FrontController servlet code into new projects
- create persistence.xml and MANIFEST.MF manifest in src\META-INF
- update manifest
   Class-Path: APP-INF/lib/eclipselink.jar 
    APP-INF/lib/javax.persistence_2.0.0.v200911041116.jar

- copy both javax.persistence 2.0 and eclipselink 2.x jars to APP-INF/lib
- change ordering of WebLogic library modules classpath reference (javax.persistence 1.0) to ear reference (2.0 version)
- update web.xml with servlet tags
- update weblogic.xml with new context root
- make the persistence unit name the same in persistence.xml and ApplicationManagedService
- update weblogic-application.xml with prefer-application-packages overrides
    <wls:prefer-application-packages>
        <wls:package-name>javax.persistence.*</wls:package-name>
        <wls:package-name>org.eclipse.persistence.*</wls:package-name>
    </wls:prefer-application-packages>
- enable server redirect logging
            <!-- new for 10.3.3.0 http://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging#Server_Logging  -->
            <property name="eclipselink.logging.logger" value="DefaultLogger"/>
- start WebLogic 10.3.3.0
- deploy (run on) server from eclipse or export ear to auto deploy directory

>posted EAR's pending
Comment 5 Michael OBrien CLA 2010-12-07 12:53:56 EST
Created attachment 184739 [details]
Application managed SE PU EAR (needs eclipselink.jar put back in) runs JPA 2.0 code and JPA 2.0 XSD schema
Comment 6 Michael OBrien CLA 2010-12-07 12:54:35 EST
Created attachment 184740 [details]
Application managed SE PU EAR and WAR Eclipse project source (needs eclipselink.jar put back in) runs JPA 2.0 code and JPA 2.0 XSD schema
Comment 7 Michael OBrien CLA 2010-12-07 12:59:29 EST
Use of the 2.0 JPA scheama currently does not work with an EE application.
However an SE persistence unit in an application managed EAR works fine with the overrides described above.

See the attached EAR and (EAR/WAR Eclipse source) above for a reproduction

>We will reopen and revisit this but when the next version of WebLogic ships
>retesting will let us know if all these workarounds are no longer needed for SE or EE JPA 2.0 apps
Comment 8 Michael OBrien CLA 2010-12-08 20:30:37 EST
I didn\t realize we had this 6th forum for the past 3 years
http://www.eclipse.org/forums/index.php?t=msg&goto=644000&S=40e13288641c0af5dc8489343b896348#msg_644000
Comment 9 Michael OBrien CLA 2011-01-19 18:06:12 EST
>This issue is deprecated by the details of bug # 334468
Comment 10 Eclipse Webmaster CLA 2022-06-09 10:05:08 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink