7 Replies Latest reply on Jan 10, 2009 2:14 PM by Javid Jamae

    Hibernate SessionFactory Injection

    Javid Jamae Newbie

      I'm trying to figure out how to inject a SessionFactory into an EJB in JBoss 5.0.0 CR2. I'm getting the following error:

      23:26:32,125 ERROR [AbstractKernelController] Error installing to Real: name=vfszip:/C:/jboss-5.0.0.CR2/server/enterpris
      e/deploy/video.ear state=PreReal mode=Manual requiredState=Real
      org.jboss.deployers.spi.DeploymentException: Error deploying video.jar: Can't find a persistence unit named 'java:/hiber
      nate/jbia/VideoSF' in AbstractVFSDeploymentContext@30349620{vfszip:/C:/jboss-5.0.0.CR2/server/enterprise/deploy/video.ea
      r/video.jar}
       at org.jboss.ejb3.deployers.Ejb3Deployer.deploy(Ejb3Deployer.java:209)
       at org.jboss.ejb3.deployers.Ejb3Deployer.deploy(Ejb3Deployer.java:108)
       at org.jboss.deployers.vfs.spi.deployer.AbstractVFSRealDeployer.internalDeploy(AbstractVFSRealDeployer.java:45)
       at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
       at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:169)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1285)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1003)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1056)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:944)
       at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
       at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
       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:627)
       at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:541)
       at org.jboss.system.server.profileservice.ProfileServiceBootstrap.loadProfile(ProfileServiceBootstrap.java:265)
       at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:143)
       at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:409)
       at org.jboss.Main.boot(Main.java:209)
       at org.jboss.Main$1.run(Main.java:544)
       at java.lang.Thread.run(Thread.java:619)
      Caused by: java.lang.IllegalArgumentException: Can't find a persistence unit named 'java:/hibernate/jbia/VideoSF' in Abs
      tractVFSDeploymentContext@30349620{vfszip:/C:/jboss-5.0.0.CR2/server/enterprise/deploy/video.ear/video.jar}
       at org.jboss.jpa.resolvers.DefaultPersistenceUnitDependencyResolver.resolvePersistenceUnitSupplier(DefaultPersis
      tenceUnitDependencyResolver.java:141)
       at org.jboss.ejb3.Ejb3Deployment.resolvePersistenceUnitSupplier(Ejb3Deployment.java:841)
       at org.jboss.ejb3.EJBContainer.resolvePersistenceUnitSupplier(EJBContainer.java:1399)
       at org.jboss.injection.PersistenceUnitHandler.addPUDependency(PersistenceUnitHandler.java:124)
       at org.jboss.injection.PersistenceContextHandler.loadXml(PersistenceContextHandler.java:76)
       at org.jboss.ejb3.EJBContainer.processMetadata(EJBContainer.java:570)
       at org.jboss.ejb3.Ejb3Deployment.processEJBContainerMetadata(Ejb3Deployment.java:439)
       at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:552)
       at org.jboss.ejb3.deployers.Ejb3Deployer.deploy(Ejb3Deployer.java:202)
       ... 23 more
      


      I have an EAR called video.ear with three modules: video.war, video.har, and video.jar.

      Here is my application.xml:
      
      <application>
       <display-name>Video</display-name>
       <module>
       <web>
       <web-uri>video.war</web-uri>
       <context-root>/video</context-root>
       </web>
       </module>
       <module>
       <ejb>video.jar</ejb>
       </module>
       <module>
       <ejb>video.har</ejb>
       </module>
      </application>
      


      (I tried taking out the video.har module since its in my jboss-app.xml, but that didn't make a difference).

      Here is my jboss-app.xml
      <!DOCTYPE jboss-app PUBLIC "-//JBoss//DTD Java EE Application 5.0///EN"
       "http://www.jboss.org/j2ee/dtd/jboss-app_5_0.dtd">
      <jboss-app>
       <module><har>video.har</har></module>
      </jboss-app>
      


      Here is my video.ear/video.har/META-INF/video-hibernate.xml:

      <hibernate-configuration xmlns="urn:jboss:hibernate-deployer:1.0">
      
       <session-factory name="java:/hibernate/jbia/VideoSF" bean="jboss.test.har:service=Hibernate,testcase=TimersUnitTestCase">
       <property name="datasourceName">java:/${db.datasource}</property>
       <property name="dialect">${db.dialect}</property>
       <property name="sessionFactoryInterceptor">org.jboss.test.hibernate.SimpleInterceptor</property>
       <property name="hbm2ddlAuto">create-drop</property>
       <depends>jboss:service=Naming</depends>
       <depends>jboss:service=TransactionManager</depends>
       <depends>jboss.jca:service=DataSourceBinding,name=${db.datasource}</depends>
       </session-factory>
      
      </hibernate-configuration>
      
      


      Here is the injection in my bean:
      @Stateless
      public class VideoServiceImpl implements VideoService {
       @PersistenceContext(unitName = "java:/hibernate/jbia/VideoSF")
       private Session hs;
      


      Any ideas? Are there any unit tests that demonstrate how to do this?

      Thanks,
      Javid