OK. I think that know the answer to this one: it's 1st come 1st win processing.
As the META-INF/orm.xml is found in the root of the PU, it's not looked up
again. According to the spec (6.2.1.6), this is wrong:
"If multiple mapping files are specified (possibly including one or more orm.xml
files), the resulting mappings are obtained by combining the mappings from all
of the files."
Can you please file a bug?
thanks,
-marina
Wonseok Kim wrote:
> My testcase shows that META-INF/orm.xml files located in ref jars are
> not processed as well as specified mapping files located in ref jars and
> classpath.
> I attach a test application for this issue.
>
> Test EAR structure
> pu.jar - the persistence unit root
> META-INF/persistence.xml
> META-INF/orm.xml - has mapping for EntityA1
> map.xml - has mapping for EntityA2
> entity/EntityA1
> entity/EntityA2
>
> ref1.jar - the referenced jar file1 from the persistence unit
> META-INF/orm.xml - has mapping for EntityB1
> map1.xml - has mapping for EntityB2
> entity/EntityB1
> entity/EntityB2
> entity/NonEntity
>
> ref2.jar - the referenced jar file2 from the persistence unit
> META-INF/orm.xml - has mapping for EntityC1
> map2.xml - has mapping for EntityC2
>
> lib.jar - the common library classes
> map3.xml - has mapping for EntityD
> entity/EntityC1
> entity/EntityC2
> entity/EntityD
>
> ejb.jar - Test EJB
> client.jar - Client which invokes Test EJB
>
> persistence.xml
> ...
> <persistence-unit name="pu1">
> <jta-data-source>jdbc/__default</jta-data-source>
> <mapping-file>map.xml</mapping-file>
> <mapping-file>map1.xml</mapping-file>
> <mapping-file>map2.xml</mapping-file>
> <mapping-file>map3.xml</mapping-file>
> <jar-file>ref1.jar</jar-file>
> <jar-file>ref2.jar</jar-file>
> ...
>
> As you can see there are multiple orm.xml files, but the orm.xml (and
> map.xml) located in PU root was processed.
> EJB Test just call em.find() to check entity classes are processed as
> "entity" and log if it fails.
> Test result log is:
> ----------
> [#|2006-09-12T11:06:20.773+0900|WARNING|sun-appserver-ee9.1|javax.enterprise.system.stream.err|_ThreadID=15;_ThreadName=p:
> thread-pool-1; w:
> 3;_RequestID=726c6adb-1573-41ae-8a2b-1f7a10f1f800;|FAIL: entity.EntityB1
> should be entity class|#]
>
> [#|2006-09-12T11:06:20.781+0900|WARNING|sun-appserver-ee9.1|javax.enterprise.system.stream.err|_ThreadID=15
> ;_ThreadName=p: thread-pool-1; w:
> 3;_RequestID=726c6adb-1573-41ae-8a2b-1f7a10f1f800;|
> FAIL: entity.EntityB2 should be entity class|#]
>
> [#|2006-09-12T11:06:20.782+0900|WARNING|sun-appserver-ee9.1|javax.enterprise.system.stream.err|_ThreadID=15
> ;_ThreadName=p: thread-pool-1; w:
> 3;_RequestID=726c6adb-1573-41ae-8a2b-1f7a10f1f800;|
> FAIL: entity.EntityC1 should be entity class|#]
>
> [#|2006-09-12T11:06:20.786+0900|WARNING|sun-appserver-ee9.1|javax.enterprise.system.stream.err|_ThreadID=15
> ;_ThreadName=p: thread-pool-1; w:
> 3;_RequestID=726c6adb-1573-41ae-8a2b-1f7a10f1f800;|
> FAIL: entity.EntityC2 should be entity class|#]
>
> [#|2006-09-12T11:06:20.787+0900|WARNING|sun-appserver-ee9.1|javax.enterprise.system.stream.err|_ThreadID=15
> ;_ThreadName=p: thread-pool-1; w:
> 3;_RequestID=726c6adb-1573-41ae-8a2b-1f7a10f1f800;|
> FAIL: entity.EntityD should be entity class|#]
> ----------
> Only EntityA1, EntityA2 are processed as Entity class.
>
> Thanks
> -Wonseok
>
> On 9/12/06, * Marina Vatkina* <Marina.Vatkina_at_sun.com
> <mailto:Marina.Vatkina_at_sun.com>> wrote:
>
> Hi Wonseok,
>
> Very good point about more than one resource.
>
> PersistenceUnitProcessor.createInputStreamForFileInPersistenceUnit
> the 1st thing it does - looks for the mapping files located in a jar.
>
> Attached test proves that it does look in a jar as it complains about
> not found classes. Which brings up another questions: am I doing
> something wrong there, or is it another bug: 2 out of 3 entities
> listed in the mapping file(s) and located in that ref-ed jar can't be
> loaded (so they are ignored - the 3rd bug?).
>
> thanks,
> -marina
>
> Wonseok Kim wrote On 09/10/06 23:05,:
> > Hi, Marina
> >
> > I agree that orm.xml or mapping files in the PU root should be
> used if
> > there are multiple same name files in the classpath.
> > But if there is no one in PU root and we pick one of the same name
> > mapping files in the classpath, it can be unpredictable.
> > How about throwing an exception in that case? Of course if there
> is one
> > mapping file in the classpath, it should work.
> > If you agree with this, the 4th step should call getResources() and
> > check the number of returned resources.
> >
> > I'm now curious that current impl can process several
> META-INF/orm.xml
> > files which exist in referenced jar files from persistence.xml. You
> > mentioned it is accomplished by current impl, but I couldn't find
> it in
> > the code... please instruct me.
> >
> > Thanks
> > - Wonseok
> >
> > On 9/9/06, *Marina Vatkina* <Marina.Vatkina_at_sun.com
> <mailto:Marina.Vatkina_at_sun.com>
> > <mailto:Marina.Vatkina_at_sun.com <mailto:Marina.Vatkina_at_sun.com>>>
> wrote:
> >
> > Team,
> >
> > Do you have any idea of a simpler/better/nicer solution for
> locating
> > mapping
> > files in a PU?
> >
> > thanks,
> > -marina
> >
> > -------- Original Message --------
> > From: mvatkina_at_dev.java.net <mailto:mvatkina_at_dev.java.net>
> <mailto:mvatkina_at_dev.java.net <mailto:mvatkina_at_dev.java.net>>
> > Subject: [Issue 1074] Regression: TopLink does not serach
> classpath
> > for mapping
> > files specified in persistence.xml
> >
> > https://glassfish.dev.java.net/issues/show_bug.cgi?id=1074
> >
> >
> >
> > User mvatkina changed the following:
> >
> > What |Old value |New value
> >
> ================================================================================
>
> >
> > Status|NEW |STARTED
> >
> --------------------------------------------------------------------------------
> >
> >
> >
> >
> > ------- Additional comments from mvatkina_at_dev.java.net
> <mailto:mvatkina_at_dev.java.net>
> > <mailto:mvatkina_at_dev.java.net <mailto:mvatkina_at_dev.java.net>>
> Fri Sep 8 20:41:35 +0000
> > 2006 -------
> > Here is what I learned about the current implementation:
> >
> > 1. Because there can be more than 1 persistence.xml on the
> classpath,
> > META-INF/orm.xml or any other mapping file referenced from a
> > persistence.xml,
> > must be 1st looked up in the PU root or in any jar file
> referenced
> > from that
> > persistence.xml. Otherwise we can get some other PU's mapping
> files
> > that are
> > accidentally on the classpath (is it a spec oversight that
> there is
> > no PU name
> > in the mapping file?).
> > This is accomplished by steps 1 and 2 in
> >
> PersistenceUnitProcessor.createInputStreamForFileInPersistenceUnit().
> >
> > 2. In Tomcat the PU root is returned by a complicated URL
> that is
> > handled by
> > step 3 in the above method.
> >
> > The solution would be to add getResourceAsStream call as the 4th
> > step, but it's
> > not clear if we should attempt to do so for the default
> mapping file
> > (META-INF/orm.xml).
> >
> >
>
>
>