[hibernate-issues] [Hibernate-JIRA] Resolved: (EJB-174) Ejb3Configuration can't open EJB Jar file with persistence.xml in Oracle OC4J server (Jifeng Liu)

Emmanuel Bernard (JIRA) noreply at atlassian.com
Mon Aug 28 19:48:26 EDT 2006


     [ http://opensource.atlassian.com/projects/hibernate/browse/EJB-174?page=all ]
     
Emmanuel Bernard resolved EJB-174:
----------------------------------

    Fix Version: 3.2.0.cr2
     Resolution: Fixed
      Assign To: Emmanuel Bernard

Applied.
Thanks and please test :-)

> 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
>         Type: Bug

>   Components: EntityManager
>     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.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list