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

Bug 342904

Summary: NoClassDefFoundError CriteriaBuilder when used with ECF
Product: z_Archived Reporter: Ajay <ajay.upadhyaya>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: ajay.upadhyaya, douglas.clarke, scastrianni, shaun.smith, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: simple_fix
Attachments:
Description Flags
fix to bnd file for imports. none

Description Ajay CLA 2011-04-14 18:17:20 EDT
Build Identifier: 2.2.0.v20110202-r8913

It looks like the org.eclipse.persistence.jpa.osgi plugin needs to import the package javax.persistence.criteria


java.lang.NoClassDefFoundError: javax/persistence/criteria/CriteriaBuilder
	at $Proxy0.getCriteriaBuilder(Unknown Source) ~[na:na]
	at com.example.MyService.createCriteriaBuilder(MyService.java:31) ~[na:na]
	at sun.reflect.GeneratedMethodAccessor32.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_18]
	at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_18]
	at org.eclipse.ecf.provider.remoteservice.generic.RemoteServiceRegistrationImpl.callService(RemoteServiceRegistrationImpl.java:356) ~[na:na]
	at org.eclipse.ecf.provider.remoteservice.generic.RegistrySharedObject$11.run(RegistrySharedObject.java:1375) ~[na:na]
	at org.eclipse.equinox.concurrent.future.SingleOperationFuture$1.run(SingleOperationFuture.java:96) ~[na:na]
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) ~[na:na]
	at org.eclipse.equinox.concurrent.future.SingleOperationFuture.runWithProgress(SingleOperationFuture.java:89) ~[na:na]
	at org.eclipse.ecf.core.jobs.JobsExecutor.safeRun(JobsExecutor.java:52) ~[na:na]
	at org.eclipse.ecf.core.jobs.JobsExecutor$1.run(JobsExecutor.java:79) ~[na:na]
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54) ~[na:na]
Caused by: java.lang.ClassNotFoundException: javax.persistence.criteria.CriteriaBuilder
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:506) ~[na:na]
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422) ~[na:na]
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410) ~[na:na]
	at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107) ~[na:na]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:248) ~[na:1.6.0_18]
	... 16 common frames omitted

Reproducible: Always
Comment 1 Tom Ware CLA 2011-05-12 15:35:03 EDT
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 2 scastria CLA 2011-06-21 23:44:16 EDT
I got the same problem with just a simple test program using JPA classes.  My OSGI command line app would not start with the same error.  I hacked the manifest of org.eclipse.persistence.jpa.osgi to add the import of javax.persistence.criteria and it worked!  I tested this on Indigo RC4 with EclipseLink 2.3.0.  So perhaps this is still a real bug.
Comment 3 Shaun Smith CLA 2011-06-28 13:50:02 EDT
I've reproduced the problem and have confirmed that adding the two imports below to the o.e.p.jpa.osgi bundle's manifest allows me to run code in OSGi that uses both the Criteria API and Metamodel classes.  The source of the problem is that the classloader associated with the persistence unit is constructed in o.e.p.jpa.osgi.PersistenceProvider.getClassLoader using the o.e.p.jpa.osgi bundle as one of the classloaders in the composite classloader.  The recent refactoring of the OSGi code out of o.e.p.jpa into o.e.p.jpa.osgi missed these imports as they aren't referenced directly.

Missing imports:

 javax.persistence.criteria;jpa="2.0",
 javax.persistence.metamodel;jpa="2.0",

Sample code:

	em = emf.createEntityManager();
	CriteriaBuilder cb = emf.getCriteriaBuilder();
	CriteriaQuery<Person> query = cb.createQuery(Person.class);
	Root<Person> person = query.from(Person.class);
	Predicate nameIsBob = cb.equal(person.get(Person_.name),"Bob");
	query.select(person).where(nameIsBob);
	Person bob = em.createQuery(query).getSingleResult();

The imports above have to be added to the BND template but when I do so I get the error below.  I'm reassigning to Eric for resolution and I can verify the fix.

bnd-package:
      [bnd] Warnings
      [bnd] Did not find matching referal for javax.persistence.criteria.*
      [bnd] Did not find matching referal for javax.persistence.metamodel.*
      [bnd] Did not find matching referal for javax.persistence.spi.*
Comment 4 Eric Gwin CLA 2011-06-28 14:59:26 EDT
Created attachment 198768 [details]
fix to bnd file for imports.

I don't see the problem you describe..

bnd-package:
      [bnd] Warnings
      [bnd] Did not find matching referal for javax.persistence.criteria.*
      [bnd] Did not find matching referal for javax.persistence.metamodel.*
      [bnd] Did not find matching referal for javax.persistence.spi.*

The attached patch works for me...

bnd-package:
      [bnd] # org.eclipse.persistence.jpa.osgi (org.eclipse.persistence.jpa.osgi_2.3.1.qualifier.jar) 13
      [jar] Building jar: D:\_EL_2.3.x\plugins\org.eclipse.persistence.jpa.osgi.source_2.3.1.qualifier.jar
Comment 5 Shaun Smith CLA 2011-06-28 15:08:17 EDT
The patch works great for me running outside PDE.  Can you also include a patch for the Manifest.MF so it reflects the change to the BND template?
Comment 6 Eric Gwin CLA 2011-06-29 11:20:38 EDT
I cannot merge the generated manifest directly because there are other changes needed, and those changes will need to be mirrored in the other projects. Tom is planning on globally updating the manifests on 2.3 soon. 

Trunk will also be changing in a few days. I've been asked to go ahead and switch 2.4.0 to use Tycho, so I don't plan on merging this fix to Trunk -  only to remove BND completely a day or so later.

In the meantime, the import section of the checked-in manifest can be replaced with the one below to fix the issue within PDE:

Import-Package: javax.persistence;jpa="2.0",javax.persistence.criteria
 ;jpa="2.0",javax.persistence.metamodel;jpa="2.0",javax.persistence.sp
 i;jpa="2.0",org.eclipse.persistence.exceptions,org.eclipse.persistenc
 e.internal.jpa.deployment,org.eclipse.persistence.internal.localizati
 on,org.eclipse.persistence.jpa,org.eclipse.persistence.logging,org.os
 gi.framework,org.osgi.service.jpa,org.osgi.service.packageadmin
Comment 7 Eric Gwin CLA 2011-06-30 09:42:44 EDT
Tom has updated the manifests on the 2.3 branch.. I'll now merge the changes.
Comment 8 Eric Gwin CLA 2011-06-30 10:11:11 EDT
merged to both trunk and 2.3. figured better to be in sync. despite pending changes on trunk.
Comment 9 Eclipse Webmaster CLA 2022-06-09 10:27:59 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink