Skip to content

PersistenceUnitReader#determinePersistenceUnitRootUrl returns wrong root url on JBoss 5, causing no detection of entity beans [SPR-5784] #10454

Closed
@spring-projects-issues

Description

@spring-projects-issues

Antony Stubbs opened SPR-5784 and commented

I have a problem with jpa/spring/hiberante/jboss not detecting my entity beans. The following is what I tracked it down to. Let me know what you think. I'm a bit new with JPA so I might have missed something of course.

The JPA spec in section 2.6 defines the root of the persistence unit to be:

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 JavaEE,
the root of a persistence unit may be one of the following:
• an EJB-JAR file
• theWEB-INF/classes directory of a WAR file[40]
• a jar file in theWEB-INF/lib directory of a WAR file
• a jar file in the root of the EAR
• a jar file in the EAR library directory
• an application client jar file

However, when I deploy onto jboss, this method returns:
vfszip:/Users/antonystubbs/Applications/jboss-5.0.1.GA/server/default/deploy/Web-marCom-1.0-SNAPSHOT/WEB-INF/lib/Backend-1.0-SNAPSHOT.jar/META-INF/persistence-spring.xml
instead of what I expected:
vfszip:/Users/antonystubbs/Applications/jboss-5.0.1.GA/server/default/deploy/Web-marCom-1.0-SNAPSHOT/WEB-INF/lib/Backend-1.0-SNAPSHOT.jar

I believe this to be because the URL originalURL = resource.getURL(); call in #determinePersistenceUnitRootUrl returns a url which is missing the jar file separator (!/) for some reason, even though the it is actually within a jar, within a war (same problem with exploded war).

As per the javadoc for ResourceUtils.extractJarFileURL(originalURL);, the behaviour is correct, in that "(which may point to a resource in a jar file or to a jar file itself)." which is what it ends up with, but I don't think this is spec compliant.?

I have attached the PersistenceUnitPostProcessor which I use to correctly point to the Backkend.jar, which allows hibernate to correctly automatically locate all my entity beans. Otherwise, it doesn't find any. Which is simply (and not very carefully):

public void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo pui) {
     URL rootUrl = pui.getPersistenceUnitRootUrl();
     String newRootUrl = rootUrl.toString();
     int metaInfIndex = newRootUrl.indexOf( "META-INF" );
     // these aren't the droids you're looking for
     if (metaInfIndex == -1)
         return;
     newRootUrl = newRootUrl.substring( 0, metaInfIndex - 1 );
     try {
         pui.setPersistenceUnitRootUrl( new URL( newRootUrl ) );
     } catch (MalformedURLException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
     }
 }

Affects: 2.5.6

Attachments:

Issue Links:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions