[
http://opensource.atlassian.com/projects/hibernate/browse/EJB-174?page=co...
]
Mikhail Fedorov commented on EJB-174:
-------------------------------------
It is dummy path to remove this error after first look to code (3am :), ).
//file Ejb3Configuration
private void scanForClasses(URL jar, List<String> packages, List<String>
entities, List<NamedInputStream> hbmFiles, boolean[] detectedArtifacts, boolean
searchORM) {
if (jar == null) {
log.error( "Container is providing a null PersistenceUnitRootUrl: discovery
impossible");
return;
}
try {
//Path ....
String url1=jar.getFile();
if (url1.startsWith("code-source")){
url1=url1.replace("code-source","file");
}
if (url1.startsWith("/")){
url1="file:"+url1;
}
if (url1.endsWith("!/")){
url1=url1.replace("!/","");
}
jar = new URL(url1);
//End Path
JarVisitor visitor = JarVisitor.getVisitor( jar, getFilters( detectedArtifacts,
searchORM, null ) );
addScannedEntries( visitor, entities, packages, hbmFiles, null );
}
catch (RuntimeException e) {
throw new RuntimeException( "error trying to scan <jar-file>: " +
jar.toString(), e );
}
catch( IOException e ) {
throw new RuntimeException( "Error while reading " + jar.toString(), e );
}
}
Ejb3Configuration can't open EJB Jar file with persistence.xml in
Oracle OC4J server (Jifeng Liu)
-------------------------------------------------------------------------------------------------
Key: EJB-174
URL:
http://opensource.atlassian.com/projects/hibernate/browse/EJB-174
Project: Hibernate Entity Manager
Issue Type: Bug
Components: EntityManager
Affects Versions: 3.1.0.Beta8
Environment: Hibernate core 3.2rc1; Hibernate Annotation 3.1.0 beta 10
Oracle OC4J 10.1.13
Oracle 9
Reporter: Jifeng Liu
Assignee: Emmanuel Bernard
Priority: Minor
Fix For: 3.2.0.cr2
In Oracle OC4J server, I created an EJB jar file, ejbSenior.jar, and put persistence.xml
in its /META-INF folder. After deploying this EJB jar, I called
javax.persistence.Persistence.createEntityManagerFactory("hibernate"). I got the
following debug information and exception stack trace:
14:36:23 DEBUG Ejb3Configuration - Archive to be processed by hibernate Entity Manager
implementation found
14:36:23 DEBUG JarVisitor - Searching mapped entities in jar/par:
code-source:/C:/my/ws31/NewOC4J/ora92/j2ee/home/applic
ations/SeniorApps/ejbSenior.jar
14:36:23 DEBUG Ejb3Configuration - Persistence unit name: hibernate
14:36:23 DEBUG Ejb3Configuration - emname:hibernate metadata: hibernate
14:36:23 WARN InputStreamZippedJarVisitor - Unable to find file (ignored):
code-source:/C:/my/ws31/NewOC4J/ora92/j2ee/h
ome/applications/SeniorApps/ejbSenior.jar
java.io.IOException:
code-source:/C:/my/ws31/NewOC4J/ora92/j2ee/home/applications/SeniorApps/ejbSenior.jar has
no "!<pat
h>" suffix so does not name a path within the code-source.
at
oracle.classloader.SharedCodeSourceSet.getResourceStream(SharedCodeSourceSet.java:482)
at
oracle.classloader.SharedCodeSourceURL$Connection.getInputStream(SharedCodeSourceURL.java:93)
at java.net.URL.openStream(URL.java:1007)
at
org.hibernate.ejb.packaging.InputStreamZippedJarVisitor.doProcessElements(InputStreamZippedJarVisitor.java:33)
at org.hibernate.ejb.packaging.JarVisitor.getMatchingEntries(JarVisitor.java:208)
at
org.hibernate.ejb.Ejb3Configuration.addMetadataFromVisitor(Ejb3Configuration.java:201)
at
org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:183)
at
org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:114)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:27)
at
com.senior.dal.shared.util.HbSessionFactory.getEntityManagerFactory(HbSessionFactory.java:40)
After debugging it, I found Oracle OC4J's class loader creates a special URL with
protocol 'code-source'. You can use this URL to get any resource inside EJB jar
file. But you can't use it to read the EJB jar file itself.
I wrote a small patch to fix it by changing the URL to an URL pointing to a file:
In org.hibernate.ejb.packaging.JarVisitor java file, I add new code between "patch
begins" and "patch ends" comment:
public static final URL getJarURLFromURLEntry(URL url, String entry) throws
IllegalArgumentException {
URL jarUrl;
String file = url.getFile();
if ( ! entry.startsWith( "/" ) ) entry = "/" + entry;
file = file.substring( 0, file.length() - entry.length() );
if ( file.endsWith( "!" ) ) file = file.substring( 0, file.length() - 1 );
try {
if ( "jar".equals( url.getProtocol() ) ) {
jarUrl = new URL( file );
}
// patch starts
else if ("code-source".equals( url.getProtocol() ) ) {
jarUrl = new File(file).toURL();
}
// patch ends
else {
jarUrl = new URL( url.getProtocol(), url.getHost(), url.getPort(), file );
}
}
catch (MalformedURLException e) {
throw new IllegalArgumentException(
"Unable to determine JAR Url from " + url + ". Cause: " +
e.getMessage()
);
}
return jarUrl;
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira