Topic
7 replies Latest Post - ‏2011-03-04T19:09:31Z by FlorianP.
FlorianP.
FlorianP.
9 Posts
ACCEPTED ANSWER

Pinned topic SCA and JPA

‏2011-03-02T18:07:24Z |
RSA 8, WAS 7, SCA and JPA 2.0 feature packs
I have an SCA component with a Java implementation and a web service binding. My Java implementation uses JPA for persistence. No matter how I try to configure my projects (1 project with everything, 1 SCA project + 1 JPA project...), I can't get JPA to work properly. Specifically, my JPA beans are not being enhanced, which ends up in an exception being thrown.
Does anybody have an example of a working configuration? I'm very open about the packaging and can do whatever it takes. Thanks!
Updated on 2011-03-04T19:09:31Z at 2011-03-04T19:09:31Z by FlorianP.
  • SystemAdmin
    SystemAdmin
    126 Posts
    ACCEPTED ANSWER

    Re: SCA and JPA

    ‏2011-03-02T18:21:40Z  in response to FlorianP.
    Hi Florian.

    What exactly do you mean with "my JPA beans are not being enhanced"? And, what's the exception you got?

    "Software development has been, is, and will remain fundamentally hard"
    - Grady Booch
    • FlorianP.
      FlorianP.
      9 Posts
      ACCEPTED ANSWER

      Re: SCA and JPA

      ‏2011-03-02T18:47:53Z  in response to SystemAdmin
      Hi Victor, here is the exception:
      3/2/11 12:52:11:337 EST 00000024 DataAccessorI E Error parsing entity types for application HiltonDemo
      <openjpa-2.0.1-SNAPSHOT-r422266:980199 fatal user error> org.apache.openjpa.util.MetaDataException: The type "class com.ibm.bedl.jpa.Charge" has not been enhanced.
      at org.apache.openjpa.meta.ClassMetaData.resolveMeta(ClassMetaData.java:1812)
      at org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1786)
      at org.apache.openjpa.meta.MetaDataRepository.processBuffer(MetaDataRepository.java:790)
      at org.apache.openjpa.meta.MetaDataRepository.resolveMeta(MetaDataRepository.java:693)
      at org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:617)
      at org.apache.openjpa.meta.MetaDataRepository.getMetaDataInternal(MetaDataRepository.java:385)
      at org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:358)
      at org.apache.openjpa.persistence.meta.MetamodelImpl.<init>(MetamodelImpl.java:87)
      at org.apache.openjpa.persistence.EntityManagerFactoryImpl.getMetamodel(EntityManagerFactoryImpl.java:338)
      at org.apache.openjpa.persistence.EntityManagerImpl.getMetamodel(EntityManagerImpl.java:1730)
      at com.ibm.bedl.runtime.impl.data.DataAccessorImpl.parseEntityTypes(DataAccessorImpl.java:71)
      (...)
  • HasanMuhammad
    HasanMuhammad
    8 Posts
    ACCEPTED ANSWER

    Re: SCA and JPA

    ‏2011-03-02T20:05:47Z  in response to FlorianP.
    SCA FEP supports JEE resources that are explicitly wired. However, we do not support impl.java with JPA since there is no architected java:/comp space for implementation.java programs, and further we have no architected place in the SCA contribution for res-refs. If this was supported you could have tied impl.java with EntityManager by binding the @EntityManager to JNDI resource, and then wiring impl.java to this resource.

    Both OSGi and JEE define how to cope with res-refs. Hence you'll need an implementation type that is also a JPA container, e.g impl.osgi or impl.jee. For OSGI application, the OSGI FEP ships a sample called "blog" which shows how to do JPA using POJOs and Blueprint. But in SCA FEP, we dont yet have an official sample that shows how to use an OSGI application as a component implementation type.
    • sutter
      sutter
      1 Post
      ACCEPTED ANSWER

      Re: SCA and JPA

      ‏2011-03-02T20:47:38Z  in response to HasanMuhammad
      Hi,
      I am not an SCA expert, but I do know a few things about JPA... It sounds like SCA by itself does not provide a "container-like" environment that would support the necessary infrastructure for JPA managed persistence. If you combine SCA with either the OSGi or Java EE runtime, then the infrastructure would be in place.

      But, you should (key word here) be able to use JPA in a non-managed or application managed environment. In this case, you would have to ensure that your Entity classes are enhanced during your build process [1]. And, your application would have to take care of creating and managing the EntityManagerFactories and EntityManagers. It's more work on your part, but you would still have the advantage of the JPA programming model and the consistencies that it provides.

      Although a little dated (an update should be posted this month), this article [2] on developer works talks about using OpenJPA in a non-managed WAS v6.1 environment. In my mind, this usage would be similar to what is being requested here for the SCA environment. Essentially, you would be using JPA as a utility framework.

      I hope I haven't opened a can of worms for the SCA team... :-)

      HTH,
      Kevin

      [1] http://webspherepersistence.blogspot.com/2009/02/openjpa-enhancement.html
      [2] http://www.ibm.com/developerworks/websphere/techjournal/0612_barcia/0612_barcia.html
      • FlorianP.
        FlorianP.
        9 Posts
        ACCEPTED ANSWER

        Re: SCA and JPA

        ‏2011-03-04T14:52:17Z  in response to sutter
        Thanks Kevin, that helped a lot. I was already managing my entity managers, and enhancing the JPA beans at build time solved the problem (I'm still getting errors, but they're purely JPA now). [1] explains how to proceed for build-time enhancement. I used the OpenJPA eclipse plugin.

        [1] http://openjpa.apache.org/enhancement-with-eclipse.html
        • FlorianP.
          FlorianP.
          9 Posts
          ACCEPTED ANSWER

          Re: SCA and JPA

          ‏2011-03-04T19:09:31Z  in response to FlorianP.
          I also fixed my JPA errors now, and the solution is working end-to-end. Thanks again, Kevin!
    • FlorianP.
      FlorianP.
      9 Posts
      ACCEPTED ANSWER

      Re: SCA and JPA

      ‏2011-03-04T14:54:25Z  in response to HasanMuhammad
      I would still like to try you solution for my edification. Can you help me figure out how to convert my existing projects to a JEE implementation?