-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Usage of jar attribute in mapping file
PostPosted: Wed Aug 09, 2006 6:34 am 
Beginner
Beginner

Joined: Wed Aug 27, 2003 3:54 am
Posts: 28
I would like to use the "jar" attribute in my mapping file, but I have some issues. Using
Code:
<mapping jar="lib/enotary-common.jar"/>
generates an exception:
Code:
java.util.zip.ZipException: The system cannot find the path specified


Referencing a ".hbm.xml" file that is contained within the jar file by using
Code:
<mapping resource="xxx"/>
works perfectly.

When using
Code:
<mapping resource="xxx"/>
the resource should be contained in the classpath. I suppose that when I use
Code:
<mapping jar="lib/enotary-common.jar"/>
the referenced jar file should be contained in the classpath. Is this correct or am I missing something ?

Hibernate version: 3.1.3

Full stack trace of any exception that occurs:
org.hibernate.MappingException: Could not read mapping documents from jar: enotary-common.jar
at org.hibernate.cfg.Configuration.addJar(Configuration.java:529)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1469)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1433)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1325)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:651)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:877)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:846)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:419)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:241)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:152)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:219)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:115)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:781)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:572)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:415)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:241)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:152)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:219)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:115)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:781)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:572)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:415)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:241)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:152)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:253)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:331)
at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:155)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3276)
at org.apache.catalina.core.StandardContext.reload(StandardContext.java:2540)
at org.apache.catalina.servlets.ManagerServlet.reload(ManagerServlet.java:802)
at org.apache.catalina.servlets.ManagerServlet.doGet(ManagerServlet.java:350)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:551)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.util.zip.ZipException: The system cannot find the path specified
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:111)
at java.util.jar.JarFile.<init>(JarFile.java:127)
at java.util.jar.JarFile.<init>(JarFile.java:92)
at org.hibernate.cfg.Configuration.addJar(Configuration.java:526)
... 68 more


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 9:13 am 
Beginner
Beginner

Joined: Wed Aug 27, 2003 3:54 am
Posts: 28
A workaround is to use an absolute path instead of a relative path. But it remains a workaround, not a real solution and it does not make the mapping file "cross-user" friendly.
Code:
<mapping jar="c:/projects/jars/enotary-common.jar"/>


It seems that Hibernate does not use the classpath for finding the referenced jar file. Which path is it using ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 9:15 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
I am assuming that you have placed the enotary-common.jar under /WEB-INF/lib/ directory if it is a web application. Keep the enotary-common.jar outside WEB-INF directory, it should work.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 10:19 am 
Beginner
Beginner

Joined: Wed Aug 27, 2003 3:54 am
Posts: 28
Your assumption is correct. I have copied enotary-common.jar outside WEB-INF, but that has not solved the problem.

Using
Code:
<mapping jar="enotary-common.jar"/>

or
Code:
<mapping jar="/enotary-common.jar"/>

or
Code:
<mapping jar="name_of_my_webapp/enotary-common.jar"/>

or
Code:
<mapping jar="/name_of_my_webapp/enotary-common.jar"/>

results in the same ZipException: The system can not find the file specified.

PS: I am using Tomcat v4.1.30.


Top
 Profile  
 
 Post subject: <mapping jar attribute requires absolute path
PostPosted: Wed Dec 20, 2006 4:01 pm 
Newbie

Joined: Mon May 22, 2006 1:00 pm
Posts: 13
We're having this identical issue. We need to specify a fully qualified absolute path to use a jar in hibernate.cfg.xml or persistence.xml, for example:

<mapping jar="c:/persistence.jar" />

Classpath settings seem to have no impact. I saw just a couple posting on this issue with no solutions - am I missing something?

Thanks!


Top
 Profile  
 
 Post subject: 我也摸索了很久,最后得到了解决。
PostPosted: Thu Nov 20, 2008 1:48 am 
Newbie

Joined: Thu Nov 20, 2008 1:42 am
Posts: 2
我的应用程序是基于JSF的Web应用程序。

解决的思路是根据在WEB服务器端先得到应用程序的绝对路径,再加上jar文件的相对路径,如此就能正确执行了。

代码如下:

...

configuration.configure(configFile);
ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
String appRealPath = servletContext.getRealPath("/");
configuration.addJar(new File(appRealPath + "WEB-INF/lib/RightsManagementV1.jar"));
sessionFactory = configuration.buildSessionFactory();

...

注意:用此种方法,不需要在hibernate.cfg.xml中添加配置。


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.