Topic
4 replies Latest Post - ‏2013-01-15T09:01:55Z by MatthiasM.
alejandroMerchan
alejandroMerchan
3 Posts
ACCEPTED ANSWER

Pinned topic centralized persistence unit

‏2012-01-18T21:57:45Z |
Hello, sorry for my English.

it's possible create a centralized persistence unit for EJBs projects ??

thanks.

Alejandro.
Updated on 2013-01-15T09:01:55Z at 2013-01-15T09:01:55Z by MatthiasM.
  • sutter
    sutter
    94 Posts
    ACCEPTED ANSWER

    Re: centralized persistence unit

    ‏2012-01-19T14:17:11Z  in response to alejandroMerchan
    Hi Alejandro,
    You can have a common persistence unit definition, but there is no centralized location defined for a persistence unit.

    From the JPA 2.0 specification:
    "A persistence unit is defined by a persistence.xml file. The jar file or directory whose META-INF directory contains the persistence.xml file is termed the root of the persistence unit. In Java EE environments, the root of a persistence unit must be one of the following:
    • an EJB-JAR file
    • the WEB-INF/classes directory of a WAR file[80]
    • a jar file in the WEB-INF/lib directory of a WAR file
    • a jar file in the EAR library directory
    • an application client jar file

    [80] The root of the persistence unit is the WEB-INF/classes directory; the persistence.xml file is therefore contained in the
    WEB-INF/classes/META-INF directory."

    This explanation would allow you to define a "persistence jar" that would contain your persistence unit definition. This "persistence jar" could then be shared across multiple EAR or WAR files.

    Hope this helps.

    Kevin Sutter, JPA Architect, IBM WebSphere

    Message was edited by: sutter
    Updated on 2012-01-19T14:17:11Z at 2012-01-19T14:17:11Z by sutter
    • alejandroMerchan
      alejandroMerchan
      3 Posts
      ACCEPTED ANSWER

      Re: centralized persistence unit

      ‏2012-01-19T14:55:05Z  in response to sutter
      Hi sutter.

      but, is posible create a "persistence jar" and put it in a shared library and this shared library be referenced for multiples EJBs projects ??

      can the "persistence jar" could then be shared across multiple EJBs projects ??

      thanks.

      Alejandro.
      • sutter
        sutter
        94 Posts
        ACCEPTED ANSWER

        Re: centralized persistence unit

        ‏2012-01-23T15:26:55Z  in response to alejandroMerchan
        Hi Alejandro,
        In theory this should work, but we have not performed any specific testing that would confirm this usage or configuration. You are welcome to do some experimentation and provide feedback for a future effort. But, right now, the official answer is that the use of a shared library for a persistence jar would not be supported.

        Thanks,
        Kevin Sutter, JPA Architect, IBM WebSphere
        • MatthiasM.
          MatthiasM.
          1 Post
          ACCEPTED ANSWER

          Re: centralized persistence unit

          ‏2013-01-15T09:01:55Z  in response to sutter
          Hi!
          I have a similar recommendation.
          I tried the shared lib approach, but this seems not to be supported:
          "Packaging of persistence units contained within shared libraries defined using the WebSphere Application Server system management shared library feature is not supported at this time."
          http://pic.dhe.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.express.doc/info/exp/ae/cejb_packfep.html

          Are there any other possible solutions to centralize the persistence units?

          The centralized persistence units would be just a workaround for me.
          My main problem is that I have different persistence unit properties for different stages. We don't have a test database so we are forced to use test schemas.
          E.g.:
          <property name="openjpa.jdbc.Schema" value="PDMTEST" />
          where the prod schema is:
          <property name="openjpa.jdbc.Schema" value="PDM" />

          Our current solution is to substitute the persistence.xml files in our build job, but then we get different ear's for each stage.
          The most valuable solution would be to use variables in the persistence.xml like:
          <property name="openjpa.jdbc.Schema" value="${pdm_schema}" />
          Then we could define the correct schema on server level and only have one persistence.xml and one ear for each stage.
          But variable substitution seems not to work for persistence.xml files in WAS. I tried it with environment variables, websphere variables and jvm properties.

          Does someone have another hint on that topic?