how to avoid loading org.eclipse.persistence.jpa.PersistenceProvider in weblogic 14.1.1.0 version - jpa

i am using #Valid annotation at MO level to validate the input data, while it works fine with tomcat server, but during weblogic deployment i am getting below error:
Caused by: java.lang.ClassCastException: class org.eclipse.persistence.jpa.PersistenceProvider cannot be cast to class javax.persistence.spi.PersistenceProvider (org.eclipse.persistence.jpa.PersistenceProvider is in unnamed module of loader com.oracle.classloader.weblogic.LaunchClassLoader #3e92efc3; javax.persistence.spi.PersistenceProvider is in unnamed module of loader weblogic.utils.classloaders.ChangeAwareClassLoader #8ae852)
i have tried providing <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> in my persistence as before i was using default persistence unit but still the same problem.
I want to avoid loading of persistence unit from eclipselink.jar which is present at weblogic container, so that it would not get evaluated at the end.
Any help in this would be appreciated.
Hibernate JPA Version: hibernate-jpa-2.1-api-1.0.0.Final.jar:1.0.0.Final
Hibernate Validator version: hibernate-validator-5.4.0.Final.jar:5.4.0.Final

in our case for use #Valid we deleted the lines below in weblogic.xml:
<wls:package-name>javax.persistence.*</wls:package-name>
<wls:package-name>javax.persistence.spi.*</wls:package-name>

Related

Adding new class to persistence.xml throws java.lang.IllegalArgumentException: Object: Restaurants{id=null, name=Subway} is not a known entity type

I created a new entity class, and added it to the persistence.xml file.
<class>xxx.xxx.xxx.xxx.xxx.Restaurants</class>
When trying to build in Maven, I get this error:
Caused by: java.lang.IllegalArgumentException: Object: Restaurants{id=null, name=Subway} is not a known entity type.
How is this caused and how can I solve it? There are no problems with the other entity classes, but just this one.
In some of our applications we use Maven build profiles that use different persistence.xml files for testing, production, etc. http://maven.apache.org/guides/introduction/introduction-to-profiles.html

JPA metamodel not recognized with Netbeans 7.4

I have a web application that is working fine under Netbeans 7.3. When I installed it on another computer with Netbeans 7.4, all references to the JPA metamodel are now undefined.
The import statements referring to the metamodel (those ending with an underscore, like the 3rd import statement below) are not recognized :
import bfMetier.ApplicationInitialise;
import entites.Locations;
import entites.Locations_;
And when I run the project, it aborts with a «cannot find symbol Locations_» error :
SEVERE: Exception while loading the app : EJB Container initialization error
java.lang.ExceptionInInitializerError
(...)
Caused by: java.lang.RuntimeException: Uncompilable source code - cannot find symbol
symbol: class Locations_
location: package entites
at beansFacades.LocationsFacade.<clinit>(LocationsFacade.java:10)
I'm using ecclipse as the JPA 2.0 provider and running the app under Glassfish 3.1.2.2.
Is there any parameter I need to add in order for the metamodel classes to be generated?
Thanks!
I created a new java project in 7.4 and found some differences...
There is no option in context menu for generating classes from database (like 7.3).
I found this option in New Java Class... Persistence category.
The entity generated by 7.4 do not have metadata classes.
Might be, the metadata classes are no longer generated/or needed by netbeans.

EclipseLink JPA 2.0. "unknown enum constant javax.persistence.LockModeType.NONE"

I have a Glassfish v3 with a remote EJB. I use this EJB to manipulate a data base using EclipseLink. Regarding this question, i'm now trying to import the EclipseLink jars to my client application as #James suggested.
Here are the jars i have added so far, those jars are those added on the server side of my application.
eclipselink-2.3.2.jar
javax.persistence-2.0.3.jar
org.eclipse.persistence.antlr.jar
org.eclipse.persistence.asm.jar
org.eclipse.persistence.core.jar
org.eclipse.persistence.jpa.jar
org.eclipse.persistence.jpa.jpql_1.0.1.jar
org.eclipse.persistence.jpa.modelgen.jar
org.eclipse.persistence.moxy.jar
org.eclipse.persistence.oracle.jar
But when i try to compile my netbeans module, i got this error:
error: in class file javax/persistence/NamedQuery.class(javax/persistence:NamedQuery.class): unknown enum constant javax.persistence.LockModeType.NONE
Note: Attempting to workaround javac bug #6512707
warning: No processor claimed any of these annotations: [javax.ejb.Remote]
error: in class file javax/persistence/NamedQuery.class(javax/persistence:NamedQuery.class): unknown enum constant javax.persistence.LockModeType.NONE
1 error
Why?
The error seems like you have the JPA 1.0 jar first on your classpath, but need the JPA 2.0 classes.

websphere 7 and (application based) open-jpa 2

I want to not use the built in Websphere 7 jpa plugin, instead use an application WEB-INF/lib/open-jpa 2 and a proprietary persistence provider. I cannot install the OSGI and JPA 2 feature pack for Websphere.
Originally, I was getting a sax parse error simply trying to load the persistence.xml (version="2" not supported). The error was thrown by a class in open-jpa 1.2.3. When I run websphere/appserver/bin/wsjpaversion.bat, the open-jpa 1.2.3 jar is displayed. By default it overrides the open-jpa 2 jar in the app. I created a shared library containing the open-jpa 2 jar with this config option checked: 'Use an isolated class loader for this shared library'. I set my application classloader to load parent last and assigned it the new shared library resource. The 'version 2' error is gone, but there is another problem. When I try to initialize an EntityManager I get an error:
Caused by: javax.persistence.PersistenceException: Failed to load provider from META-INF/services
at javax.persistence.spi.PersistenceProviderResolverHolder$DefaultPersistenceProviderResolver.getPersistenceProviders(PersistenceProviderResolverHolder.java:121)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:91)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
... 2 more
Caused by: java.lang.ClassCastException: com.ibm.websphere.persistence.PersistenceProviderImpl incompatible with javax.persistence.spi.PersistenceProvider
at javax.persistence.spi.PersistenceProviderResolverHolder$DefaultPersistenceProviderResolver.getPersistenceProviders(PersistenceProviderResolverHolder.java:110)
... 11 more
One more detail: inside the persistence.xml, the provider element is set to the proprietary PersistenceProviderImpl not the default Websphere persistence provider. So where is this websphere default coming from and how do I prevent it? (another important note: when I remove persistence.xml completely, I get the same error)
Thank you
Without installing the feature pack, you're fighting a losing battle. While it is possible to plug in your own JPA implementation, it is not possible to do that with JPA API — so WAS 7 ties you to the 1.0 version of JPA (see, for example, here how this is done — no class loader policy juggling will change that, though it seems tempting at first).

Trouble with Aspectj load-time-weaving when using EclipseLink JPA in Spring dm Server 1.x

I am attempting to get EclipseLink JPA working inside the Spring dm Server OSGi environment.
Relevant frameworks and libraries downloaded from the Spring Enterprise Bundle Repository include:
dm Server 1.0.2.SR02
AspectJ Runtime 1.6.3
AspectJ Weaver 1.6.3
Spring Framework 2.5.6.A
Eclipse Persistence 1.1.0
Javax Persistence API 1.99.0
I followed the same structure as presented in the PetClinic-1.5.0 example for setting up EclipseLink JPA. Everything works until lazy-fetching is enabled (which requires proxied objects).
Once lazy-fetching is enabled, the following error suggests that load-time-weaving is not working correctly.
---- (truncated for readability)
Exception [EclipseLink-60] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.DescriptorExcep tion
Exception Description: The method [_persistence_setcustomer_vh] or [_persistence_getcustomer_vh] is not defined in the object [net.fractech.fds.backoffice.Job].
Internal Exception: java.lang.NoSuchMethodException: net.fractech.fds.backoffice.Job._persistence_getcu stomer_vh()
Mapping: org.eclipse.persistence.mappings.OneToOneMapping[customer]
Descriptor: RelationalDescriptor(net.fractech.fds.backoffice.J ob --> [DatabaseTable(JOBS)])
This shows that the _persistence_getcustomer_vh() and _persistence_setcustomer_vh() methods were not automatically weaved into the Job domain object.
Questions
1.) How do I determine if load-time-weaving is actually working; moreover, how do I log which load time weaving agent and weaver was started? How do I pass switches to this weaver to have it output debugging information?
I assume I started load-time-weaving with <context:load-time-weaver aspectj-weaving="on" />
2.) Many searches have revealed that I do not need to pass the -javaagent parameter to the jvm when using dm Server. Is this correct?
3.) I have assured that my domain objects in another bundle have access to the eclipse persistence classes by asserting com.springsource.org.eclipse.persistence;version="[1.1.0,1.1.0]";import-scope:=application in my eclipselink bundle and including all application bundles within a PAR. Are there any other configurations needed to enable EclipseLink JPA in Spring dm Server?
I had similar problems. First try setting eclipselink.weaving.lazy=false, or eclipselink.weaving=false if that doesn't work. I had to set the latter.
If you would like to refer to the setup I am using to see if it applies to you, I have a post about it on my site.
It is better to use Equinox Waving Springwaver
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
...
<property name="loadTimeWeaver">
<bean class="org.eclipse.equinox.weaving.springweaver.EquinoxAspectsLoadTimeWeaver"/>
</property>
</bean>
You don't need to use -javaagent option then.
You can find working examples with JPA and EclipseLink here http://code.google.com/p/springdm-in-action/ (see Chapter 7).
I have tried to use EquinoxAspectsLoadTimeWeaver into JPa context (with EclipseLink) but it doen't transform the model classes if your EquinoxAspectsLoadTimeWeaver bean declaration is not done into the same bundle than Model bundle.
EquinoxAspectsLoadTimeWeaver transform class ONLY for the classes stored into the bundle wich declare EquinoxAspectsLoadTimeWeaver.
I have tried the sample http://code.google.com/p/springdm-in-action/ (see Chapter 7) (thank for this sample Lukasz). The declaration of EquinoxAspectsLoadTimeWeaver avoid having the error
Caused by: java.lang.IllegalStateException: Cannot apply class transformer without LoadTimeWeaver specified
But Model classes are not transformed (woven). Weaving into EclipseLink manage for instance lazy mode. For instance if you set into the sample model Contact lazy mode like this :
public class Contact {
...
#Column(name="last_name")
#Basic(fetch=FetchType.LAZY)
private String lastName;
you will notice that lazy loading is not applied because Model Contact class is not wowen.
Regards Angelo