[jboss-dev] How to fix vfs?
Ales Justin
ales.justin at gmail.com
Wed Feb 18 03:48:53 EST 2009
Something fishy in JPA ...
The structure is like this:
* ejb_pkg_scope.ear
** ejb_pkg_scope.jap
*** META-INF
**** persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="CTS-SCOPE-UNIT">
<description>Persistence Unit for CTS EE Propagation Tests.
If the transaction-type is not specified,
the default is JTA.</description>
<jta-data-source>jdbc/DB1</jta-data-source>
<jar-file>lib/common.jar</jar-file>
</persistence-unit>
</persistence>
In our JPA we do this:
public void start() throws Exception
{
log.info("Starting persistence unit " + kernelName);
Properties props = new Properties();
props.putAll(defaultPersistenceProperties);
props.put(HibernatePersistence.JACC_CONTEXT_ID, getJaccContextId());
List<URL> jarFiles = new ArrayList<URL>();
Set<String> files = metaData.getJarFiles();
if (files != null)
{
for (String jar : files)
{
jarFiles.add(getRelativeURL(jar));
}
}
VirtualFile root = getPersistenceUnitRoot();
log.debug("Persistence root: " + root);
// hack the JPA url
URL url = VFSUtils.getCompatibleURL(root);
PersistenceUnitInfoImpl pi = new
PersistenceUnitInfoImpl(metaData, props, di.getClassLoader(), url,
jarFiles, initialContext);
private URL getRelativeURL(String jar)
{
try
{
return new URL(jar);
}
catch (MalformedURLException e)
{
try
{
URL url = di.getFile("").toURL();
return new URL(url, jar); <--- XXX
}
catch (Exception e1)
{
throw new RuntimeException("could not find relative path: "
+ jar, e1);
}
}
}
How should this know that it actually shouldn't go and look into .jar,
but .ear instead?
Beats me ... as XXX clearly points to .jar's path.
Shelly McGowan wrote:
>
> Ales,
>
> The packaging of this .ear is testing the following assertion defined
> in the Persistence Specification:
>
> 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-files 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 root of the
> persistence unit.**
>
> persistence.xml: <jar-file>lib/common.jar</jar-file>
>
> The persistence unit is at the root of the .ear.
>
> Shelly
More information about the jboss-development
mailing list