Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spring-projects-issues opened this issue May 25, 2009 · 5 comments
Labels
type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented May 25, 2009

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:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented May 25, 2009

Antony Stubbs commented

just in case you're interested

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented May 25, 2009

Antony Stubbs commented

The other work around for this was to explicitly list the entity classes in the persistence unit configuration, but I want to get the auto detection working.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented May 27, 2009

Marius Bogoevici commented

This is actually related to #9793

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented May 27, 2009

Antony Stubbs commented

Thanks for the link! Tried searching but couldn't find anything relevant :-/

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Sep 11, 2009

Thomas Risberg commented

I have committed the patch for #9793 and that should also fix this issue. Try a recent snapshot or the upcoming RC1 release. If it doesn't work then, please reopen this issue and if possible provide a test case.

-Thomas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant