0

I have a jar file and persitence.xml in META-INF in that jar file. I want to configure the persistence.xml with <jar-file>. Also I have a lib directory on the same folder with jar file. But I am not able find correct path for <jar-file> tag. I tried;

<jar-file>lib/entity.jar</jar-file>
<jar-file>../lib/entity.jar</jar-file>
<jar-file>./lib/entity.jar</jar-file>
<jar-file>../../lib/entity.jar</jar-file>

but no luck. Entity manager can not find the entities in entity.jar

xxlali
  • 996
  • 2
  • 15
  • 43
  • "When using jar-file, you must specify a path relative to the jar file the persistence.xml file is in". – Gimby Jul 09 '21 at 12:01
  • so, I can not do that for jar file ? – xxlali Jul 09 '21 at 12:16
  • Your first try, `lib/entity.jar`, should have worked. Are these .jar files deployed together in an .ear file or a .war file? – VGR Jul 09 '21 at 12:30
  • not ear nor war. I have only jar and it reads necessary dependencies from lib folder. Everything works except hibernate doesn't see entity.jar. – xxlali Jul 09 '21 at 14:04

1 Answers1

0

As it's stated in the JPA 2.2 specification (see section 8.2.1.6.3 Jar Files):

One or more JAR files may be specified using the jar-file elements instead of, or in addition to the mapping files specified in the mapping-file elements. If specified, these JAR files will be searched for managed persistence classes, and any mapping metadata annotations found on them will be processed, or they will be mapped using the mapping annotation defaults defined by this specification. Such JAR files are specified relative to the directory or jar file that contains[91] the root of the persistence unit.[92]

...

[91] This semantics applies to persistence.xml files written to the persistence_2_0.xsd or later schema. Due to ambiguity in the Java Persistence 1.0 specification, provider-specific interpretation of the relative references used by this element may apply to earlier versions.

[92] Persistence providers are encouraged to support this syntax for use in Java SE environments.

Your case looks like the Example 1 from the specification:

app.ear
   lib/earEntities.jar
   earRootPUnit.jar (with META-INF/persistence.xml )

persistence.xml contains: <jar-file>lib/earEntities.jar</jar-file>

But if you use JPA 1.0 it looks like you should check related part of the provider-specific documentation.

SternK
  • 11,649
  • 22
  • 32
  • 46