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

Bug 332290

Summary: EclipseLink-7198: java.lang.ClassNotFoundException: Class was not found while converting from class names to classes
Product: z_Archived Reporter: Mikael Nousiainen <mikael.nousiainen>
Component: EclipselinkAssignee: Project Inbox <eclipselink.orm-inbox>
Status: CLOSED FIXED QA Contact:
Severity: major    
Priority: P2 CC: michael.f.obrien, mikael.nousiainen, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
URL: http://www.eclipse.org/forums/index.php?t=msg&th=170950&start=0
Whiteboard:
Bug Depends on: 266912, 303063, 322585    
Bug Blocks:    
Attachments:
Description Flags
Stack traces in GlassFish logs with EcliseLink logging level set to FINEST
none
A small test case to reproduce the exception none

Description Mikael Nousiainen CLA 2010-12-10 05:42:15 EST
Build Identifier: 2.1.1.v20100817-r8050

I'm using Spring 3.0.5 and GlassFish 3.0.1 with EclipseLink 2.1.1.v20100817-r8050.

AI have the following entity classes in the example:
@MappedSuperclass class AbstractDataObject
@MappedSuperclass class AbstractNamedDataObject extends AbstractDataObject
@Entity class TestEntity extends AbstractNamedDataObject

And the following Spring components that use the entity TestEntity:
@Repository class TestRepositoryImpl
@Service class TestServiceImpl

When using a @MappedSuperclass parent class for an entity, accessing
EntityManager.getCriteriaBuilder() in TestRepositoryImpl causes
a ClassNotFoundException, when called from a @Transactional-annotated method
in TestServiceImpl.

This bug is related to an EclipseLink forum thread here:
http://www.eclipse.org/forums/index.php?t=msg&th=170950&start=0


Reproducible: Always

Steps to Reproduce:
1. Use Spring <= 3.0.5 and container manager persistence in GlassFish 3.0.1
2. Create a @MappedSuperclass parent class for an entity
3. Create a Spring @Repository class and create a method calling EntityManager.getCriteriaBuilder() for an injected @PersistenceContext EntityManager using the created entity
4. Create a Spring @Service class and call the repository method in a @Transaction-annotated method
5. Disable EclipseLink schema creation (so that no queries are run before using CriteriaBuilder)
6. Call the @Transactional-annotated method in @PostConstruct in the service
6. Deploy - it fails at deploy time
Comment 1 Mikael Nousiainen CLA 2010-12-10 05:45:34 EST
Created attachment 184935 [details]
Stack traces in GlassFish logs with EcliseLink logging level set to FINEST

Particularly one line is interesting - just before the exception there is:

[#|2010-12-10T12:13:49.238+0200|FINEST|glassfish3.0.1|org.eclipse.persistence.default|_ThreadID=29;_ThreadName=Thread-1;ClassName=null;MethodName=null;|The metamodel TypeImpl.javaClass field should not be set to null for the Type [EntityTypeImpl@302525333 [ javaType: null descriptor: null]].|#]
Comment 2 Mikael Nousiainen CLA 2010-12-10 05:48:49 EST
Created attachment 184936 [details]
A small test case to reproduce the exception

The test case requires Maven 2.2 to compile and it can be deployed in GlassFish 3.0.1.

You have to create a connection pool in GlassFish using name jdbc/TestConnectionPool
Comment 3 Mikael Nousiainen CLA 2010-12-13 10:53:47 EST
It seems that there is a workaround for this bug. If you execute any simple select query using regular JPQL query (NOT CriteriaBuilder) before using CriteriaBuilder, the application works.

So apparently something does not get initialized properly when using CriteriaBuilder or it uses an incorrect ClassLoader at some point.
Comment 4 Tom Ware CLA 2010-12-23 11:40:49 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Comment 5 Michael OBrien CLA 2010-12-23 12:56:35 EST
>This issue is very likely a reproduction of the unitialized javaClass from javaClassNam that we would like to narrow down with a good test case.
There are 2 details to be aware of...
1) in SVN rev# 8141 v20100904 a change for bug # 322485 was put in to force initializeDescriptors() on an early predeploy() (and set the javaClass preemptively) in case a getMetamodel() or getCriteriaBuilder() is called on an EntityManagerFactory before we have an EntityManager session running.
https://fisheye2.atlassian.com/changelog/eclipselink/?cs=8142
https://bugs.eclipse.org/bugs/show_bug.cgi?id=322585
2) If you are still seeing a an issue after upgrading past the 8141 revision of EclipseLink then either this or bug # 303063 or bug # 322585 should be reopened.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=303063#c25

The message "The metamodel TypeImpl.javaClass field should not be set to null for the Type" warning is a final catch-all to track any instances of bug # 303063 that still occur after a forced EMF predeploy() of the metamodel

>I am not duplicating this bug at this point to bug # 303063 until post rev # 8142 testing is done
Comment 6 Mikael Nousiainen CLA 2011-01-13 05:31:53 EST
My initial tests (using the test case provided as attachment to this bug) confirm that this bug is resolved in EclipseLink 2.1.2.
Comment 7 Tom Ware CLA 2011-01-13 08:20:54 EST
Closing based on above comments
Comment 8 Michael OBrien CLA 2011-01-13 09:27:59 EST
>Mickael, thank for verifying post rev 8141 in bug # 322585
Comment 9 Eclipse Webmaster CLA 2022-06-09 10:02:59 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink