0

So I have the following:

I am trying to override the schema from the default to a different one from the web application

I have tried combinations of:

  • using orm.xml inside WEB-INF
  • using orm.xml inside META-INF
  • using persistence.xml inside WEB-INF
  • using persistence.xml inside META-INF
  • persistence.xml has <mapping-file>META-INF/orm.xml</mapping-file>
  • persistence.xml has <mapping-file>WEB-INF/orm.xml</mapping-file>
  • persistence.xml with <persistence-unit name="same">
  • persistence.xml with <persistence-unit name="different">

To no avail. I am trying to avoid touching the web fragment and portable (so nothing EclipseLink specific like SessionCustomizer)

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265

1 Answers1

1

If you want to customize your persistence settings, you should not put persistence.xml inside your web fragment. Instead, define all the settings only in persistence.xml of your web application, plus add reference to your fragments jar using jar-file in the persistence.xml . You may define a default orm.xml file in your fragment that can be reused in web application's persistence.xml, but does not have to be.

In order to specify different default schema, define it in additional orm.xml file, as I described here. Remember that you may use more orm files for single persistence unit, you just need to name them differently. They will be searched for in classpath of the application including your fragment.

Community
  • 1
  • 1
OndroMih
  • 7,280
  • 1
  • 26
  • 44
  • Nope didn't work, I tried to do as you had stated (even without an `orm.xml` file just the `persistence.xml` file) and I get `Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName null` – Archimedes Trajano Aug 26 '15 at 16:27
  • I also tried adding the `lib/dox-rest...jar` with no luck either. – Archimedes Trajano Aug 26 '15 at 16:31
  • You request an EM for unit named null somewhere. When I'll have time to look at your vode I will look into it – OndroMih Aug 26 '15 at 17:08
  • Thanks, I don't request anything named `null` but I am relying on the default which is given by `@PersistenceUnit` with no annotations parameters – Archimedes Trajano Aug 26 '15 at 19:36
  • I made a mistake in my answer, I sometimes forget this: persistence.xml always goes into the **META-INF** folder, not into WEB-INF. Try to remove `persistence.xml` from fragment and move it to META-INF folder in the webapp. – OndroMih Aug 26 '15 at 19:55
  • I played with the app a bit and got it working with my advice above plus adding jar-file element into the `persistence.xml` in the WAR to point to dox-rest jar to search for entities there. – OndroMih Aug 26 '15 at 19:56
  • This does not solve the "no modification of the web fragment" but it may be a the only way at the moment. I have verified the solution and excepted this as the answer unless someone else can find another way :) – Archimedes Trajano Aug 26 '15 at 20:41
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/88042/discussion-between-ondrejm-and-archimedes-trajano). – OndroMih Aug 26 '15 at 21:07