Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-6636

Missing package import for javax.persistence.criteria in ORM

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 3.0 GA
    • Fix Version/s: 3.0.3
    • Component/s: Data
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      In ORM, dynamic proxies for EntityManagers are created (in SharedEntityManagerCreator.createSharedEntityManager())

      When creating dynamic proxies, all classes that the to be proxified class depends on, must be on classpath.

      Since JPA 2.0.0, EntityManager has a dependency on javax.persistence.criteria.

      Thus, a (optional) package import on javax.persistence.criteria must be added to the MANIFEST.MF of ORM bundle.

      Otherwise, we get NoClassDefFoundError for class javax.persistence.criteria.CriteriaQuery, when using @PersistenceContext in OSGi environments.

      Note: There are some cases, when this error not occurs, for example, if the EntityManagerFactory created in the same bundle as where @PersistenceContext is used and if this bundle has some import on javax.persistence.criteria.
      But in other cases, when EntityManagerFactory is provided as an OSGi-service and used by other (DAO-)Bundles, we have no chance to workaround the missin import, since in those cases, always the Bundle classloader of ORM is used:

      108 if (emf instanceof EntityManagerFactoryInfo)

      { 109 cl = ((EntityManagerFactoryInfo) emf).getBeanClassLoader(); 110 }

      111 Class[] ifcs = new Class[entityManagerInterfaces.length + 1];
      112 System.arraycopy(entityManagerInterfaces, 0, ifcs, 0, entityManagerInterfaces.length);
      113 ifcs[entityManagerInterfaces.length] = EntityManagerProxy.class;
      114 return (EntityManager) Proxy.newProxyInstance(
      115 (cl != null ? cl : SharedEntityManagerCreator.class.getClassLoader()),
      116 ifcs, new SharedEntityManagerInvocationHandler(emf, properties));

        Attachments

          Activity

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              stefanoc Stefan Ocke
              Last updater:
              Trevor Marshall
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                8 years, 11 weeks, 2 days ago