0

ZK 5.0.4 + SPRING 3.0.4 + JPA + JBOSS 5.1 -> Can't find a persistence unit named 'null' in Abstract

asked 2010-09-17 08:31:44 +0800

amar4kintu gravatar image amar4kintu
30 2

Hello friends,

I am trying to run ZK With Spring JPA And A Model-View-Controller Pattern described on link alias

I am using ZK 5.0.4 + SPRING 3.0.4 + JPA + JBOSS 5.1 for that.

Following is my WEB-INF/lib directory

commons-fileupload.jar
commons-io.jar
fckez.jar
groovy.jar
jruby.jar
js.jar
jython.jar
org.springframework.aop-3.0.4.RELEASE.jar
org.springframework.asm-3.0.4.RELEASE.jar
org.springframework.aspects-3.0.4.RELEASE.jar
org.springframework.beans-3.0.4.RELEASE.jar
org.springframework.context.support-3.0.4.RELEASE.jar
org.springframework.context-3.0.4.RELEASE.jar
org.springframework.core-3.0.4.RELEASE.jar
org.springframework.expression-3.0.4.RELEASE.jar
org.springframework.instrument.tomcat-3.0.4.RELEASE.jar
org.springframework.instrument-3.0.4.RELEASE.jar
org.springframework.jdbc-3.0.4.RELEASE.jar
org.springframework.jms-3.0.4.RELEASE.jar
org.springframework.orm-3.0.4.RELEASE.jar
org.springframework.oxm-3.0.4.RELEASE.jar
org.springframework.test-3.0.4.RELEASE.jar
org.springframework.transaction-3.0.4.RELEASE.jar
org.springframework.web.portlet-3.0.4.RELEASE.jar
org.springframework.web.servlet-3.0.4.RELEASE.jar
org.springframework.web.struts-3.0.4.RELEASE.jar
org.springframework.web-3.0.4.RELEASE.jar
zcommon.jar
zcommons-el.jar
zhtml.jar
zk.jar
zkplus.jar
zul.jar
zweb.jar

Following is my web.xml file

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>zk5</display-name>
  
  <!-- Spring -->
	
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	
	<listener>
		<!-- The Spring RequestContextLister uses thread bound variables so to 
		use this Spring freatures requires that we apply <disable-event-thread /> 
		within zk.xml -->
		<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
	</listener>
	
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:dataSourceContext.xml,classpath:spring-context.xml</param-value>
	</context-param>
	
	<!-- Spring -->
	
  <listener>
  	<description>
  	Used to cleanup when a session is destroyed</description>
  	<display-name>
  	
  	ZK Session cleaner</display-name>
  	
  	<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
  </listener>
  <servlet>
  	<description>
  	The ZK loader for ZUML pages</description>
  	<servlet-name>zkLoader</servlet-name>
  	<servlet-class>
  	org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
  	<init-param>
  		<param-name>update-uri</param-name>
  		<param-value>/zkau</param-value>
  	</init-param>
  	<load-on-startup>1</load-on-startup>
  </servlet>
  <servlet>
  	<description>
  	The asynchronous update engine for ZK</description>
  	<servlet-name>auEngine</servlet-name>
  	<servlet-class>
  	org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
  </servlet>
  <servlet-mapping>
  	<servlet-name>zkLoader</servlet-name>
  	<url-pattern>*.zul</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
  	<servlet-name>zkLoader</servlet-name>
  	<url-pattern>*.zhtml</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
  	<servlet-name>auEngine</servlet-name>
  	<url-pattern>/zkau/*</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    <welcome-file>index.zul</welcome-file>
  </welcome-file-list>
</web-app>


Following is my zk.xml file

<?xml version="1.0" encoding="UTF-8"?>

<!--
	Created by ZK Studio
-->

<zk>
	<device-config>
		<device-type>ajax</device-type>
		<timeout-uri>/timeout.zul</timeout-uri><!-- An empty URL can cause the browser to reload the same URL -->
	</device-config>
	
	<system-config>
		<!-- 
		Spring binds web scoped beans to the thread so we instructed ZK not 
		to fork threads. That will prevent you from using certain suspend/resume
		features. The line within the web.xml that requires that we disable 
		the event thread is 
		<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
		-->
		<disable-event-thread />
	</system-config>
	
</zk>

Following is my dataSourceContext.xml file

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="
	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
	">
	
	<bean id="dataSource"
		class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close" 
		p:driverClassName="${jdbc.driver}"
		p:url="${jdbc.url}"
		p:username="${jdbc.username}"
		p:password="${jdbc.password}" />

	<bean id="transactionManager"
		class="org.springframework.orm.jpa.JpaTransactionManager" 
		p:entity-manager-factory-ref="entityManagerFactory"
	/>
	
<!--
    Injected properties
    --> 
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
	    <property name="locations">
	    <list>
            <value>classpath:zktodo2.properties</value>
	    </list>
	    </property>
        
    </bean>
    

</beans>

Following is my spring-context.xml file

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="
	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
	">
    
	<!-- 
    JPA config   
    -->	
	
	<tx:annotation-driven />

	<bean id="entityManagerFactory"
		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
		p:data-source-ref="dataSource"
		p:persistence-xml-location="classpath:persistence.xml"
		>
		<property name="jpaVendorAdapter">
			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
				p:showSql="true"
				p:generateDdl="true">
			</bean>
		</property>
		<property name="jpaProperties">
			<value>
			hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
			hibernate.dialect=${hibernate.dialect}
			hibernate.hbm2ddl.auto=${hibernate.hbm2ddl.auto}
			</value>
		</property>
	</bean>

	<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

    <!-- 
    JPA helpers
    --> 
    
    <bean id="basicDao" class="org.zkforge.zktodo2.BasicDao" />

    <!-- 
    First article classes
    --> 

	<bean id="reminderService" class="org.zkforge.zktodo2.ReminderService" 
		p:basicDao-ref="basicDao"
	/>

	<bean id="toDoControllerV1" class="org.zkforge.zktodo2.ZkToDoControllerV1" 
		p:reminderService-ref="reminderService" scope="prototype"
	/>

    <!-- 
    Data binding enhancement classes
    --> 

	<!-- 
	Note that the following bean is session scoped. 
	--> 
	<bean id="toDoModel" class="org.zkforge.zktodo2.ZkToDoModelImpl" 
			p:reminderService-ref="reminderService" scope="session">
		<!-- 
		// scoped proxy is commented out as only referenced by a prototype bean
		// if you wanted to pass this bean to a singleton you need to include
		// the following configurration.   
		<aop:scoped-proxy proxy-target-class="false"/>
		-->	
	</bean>

	<bean id="toDoControllerV2" class="org.zkforge.zktodo2.ZkToDoControllerV2" 
		p:toDoModel-ref="toDoModel" scope="prototype"
	/>
    
</beans>


Following is my persistence.xml file

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
             version="1.0">
   
	<persistence-unit name="zktodo2" transaction-type="RESOURCE_LOCAL" />
	
</persistence>


Following is my zktodo2.properties file

jdbc.url=jdbc:hsqldb:file:c:/hsqldb/data/zktodo2
jdbc.username=sa
jdbc.password=
jdbc.driver=org.hsqldb.jdbcDriver
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.hbm2ddl.auto=update


Files dataSourceContext.xml, persistence.xml, spring-context.xml and zktodo.properties are under /src/ folder of the project.
Files web.xml and zk.zml are under /WEB-INF/ folder of the project.

Now when I am trying to compile my project with JBOSS 5.1 server if gives following error

18:38:49,015 ERROR  Context  startup failed due to previous errors
java.lang.IllegalArgumentException: Container org.jboss.web.tomcat.service.TomcatInjectionContainer@1372706 failed to resolve persistence unit null
	at org.jboss.injection.PersistenceUnitHandler.addPUDependency(PersistenceUnitHandler.java:135)
	at org.jboss.injection.PersistenceContextHandler.loadXml(PersistenceContextHandler.java:76)
	at org.jboss.web.tomcat.service.TomcatInjectionContainer.processMetadata(TomcatInjectionContainer.java:550)
	at org.jboss.web.tomcat.service.WebCtxLoader.start(WebCtxLoader.java:158)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4272)
	at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:310)
	at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:142)
	at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:461)
	at org.jboss.web.deployers.WebModule.startModule(WebModule.java:118)
	at org.jboss.web.deployers.WebModule.start(WebModule.java:97)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
	at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
	at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
	at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
	at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
	at org.jboss.system.microcontainer.ServiceProxy.invoke(ServiceProxy.java:206)
	at $Proxy38.start(Unknown Source)
	at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:42)
	at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:37)
	at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
	at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
	at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
	at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
	at org.jboss.system.microcontainer.ServiceControllerContext.install(ServiceControllerContext.java:286)
	at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
	at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
	at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
	at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
	at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
	at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
	at org.jboss.system.ServiceController.doChange(ServiceController.java:688)
	at org.jboss.system.ServiceController.start(ServiceController.java:460)
	at org.jboss.system.deployers.ServiceDeployer.start(ServiceDeployer.java:163)
	at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:99)
	at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:46)
	at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
	at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
	at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
	at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
	at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
	at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1178)
	at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
	at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
	at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
	at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
	at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
	at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
	at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
	at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
	at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
	at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:702)
	at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117)
	at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:362)
	at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:255)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
	at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.IllegalArgumentException: Can't find a persistence unit named 'null' in AbstractVFSDeploymentContext@10388516{vfsfile:/E:/workspace/eclipse/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_5.1_Server/deploy/zk5.war/}
	at org.jboss.jpa.resolvers.BasePersistenceUnitDependencyResolver.resolvePersistenceUnitSupplier(BasePersistenceUnitDependencyResolver.java:107)
	at org.jboss.web.tomcat.service.TomcatInjectionContainer.resolvePersistenceUnitSupplier(TomcatInjectionContainer.java:685)
	at org.jboss.injection.PersistenceUnitHandler.addPUDependency(PersistenceUnitHandler.java:130)
	... 66 more

Can any one help me solving the problem?

Please let me know if you need anything else from me.

Thanks.

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2010-09-19 23:52:59 +0800

masum gravatar image masum
33 1
www.optinfra.com

Hi amar4kintu ,
give me your mail id , I shall provide a appropriate solution for MVC architecture .

link publish delete flag offensive edit

answered 2010-09-20 00:10:20 +0800

amar4kintu gravatar image amar4kintu
30 2

Hello Masum,

My email id is [email protected]

But you can give me solution here on this page also. So that others can get help from here in future.

Thanks.

link publish delete flag offensive edit

answered 2010-09-23 00:53:25 +0800

Khosro gravatar image Khosro
48

Hi Masum,
As amar4kintu said ,please post your solution here that can be useful for others.
Khosro.

link publish delete flag offensive edit

answered 2010-11-22 17:25:54 +0800

simbo gravatar image simbo
74 2

updated 2010-11-22 17:30:41 +0800

Hi Amar,

Sorry I had not seen your post until today. Thanks for trying out my code so hard.

I have committed minor tweaks to get the sourcecode for my sample app (the one linked to on the mvc4 article) to have a cleaner web.xml for JBoss. I also upgraded my sample app to ZK5.0.5 and Spring3.0.5 and also downgraded the hibernate to 3.3.1.ga which JBoss5.1 runs.

Unfortunately after all that here is an issue with jboss running with

<tx:annotation-driven /> 

on jboss5.1. It gives an error
Error creating bean with name 'entityManagerFactory' defined in class path resource [spring-context.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: error trying to scan <jar-file>: vfsfile:/home/simon/opt/jboss-5.1.0.GA/server/default/deploy/zktodo2-1.3.war/WEB-INF/classes/

This is discussed on this jboss thread Spring Component Auto Detection. Basically you can either go the whole xml route (no nice spring annotations) or you can follow up on the approaches on that thread if you need to use jboss.

Since it is a general spring issue with Spring and the way jboss deploys files I am sure that there will be a few more posts around to get over that particular issue if you are must use jboss. Personally I know is a great container but it sure is so, so, so slow to startup and use over jetty if you just want have a zk app. Spring lets you easily do all that other stuff like sending email and whatever else most typical webapps need to do without a big j2ee container.

Simon

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-09-17 08:31:44 +0800

Seen: 2,333 times

Last updated: Nov 22 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More