14 Replies Latest reply on Oct 27, 2008 5:27 PM by Alex Ricardo

    EntityManagerFactory not found in JNDI helloworldEntityManagerFactory

    Dan Dosch Newbie

      Hello,


      I am new to Seam and trying to get my feet wet. I have been going through the Chapter 2 tutorial and all was going well until part 2.5 (seam generate-entities)


      I am using JBoss 4.2.2.GA and JBoss Seam 2.0.1.GA


      I was able to create a project and get it running successfully. Seam generate-entities was also successful as well. Seam-gen connected to my Oracle database and created the entity files and a default UI for each of them. Then when I try to view the UI, i get the following error:


      java.lang.IllegalArgumentException: EntityManagerFactory not found in JNDI : java:/helloworldEntityManagerFactory
              at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:247)
              at org.jboss.seam.persistence.ManagedPersistenceContext.initEntityManager(ManagedPersistenceContext.java:79)
              at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:108)
              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.seam.util.Reflections.invoke(Reflections.java:21)
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:125)
              at org.jboss.seam.Component.callComponentMethod(Component.java:2082)
              at org.jboss.seam.Component.unwrap(Component.java:2108)
              at org.jboss.seam.Component.getInstance(Component.java:1887)
              at org.jboss.seam.Component.getInstance(Component.java:1840)
              at org.jboss.seam.Component.getInstance(Component.java:1834)
              at org.jboss.seam.framework.Controller.getComponentInstance(Controller.java:263)
              at org.jboss.seam.framework.PersistenceController.getPersistenceContext(PersistenceController.java:20)
              at org.jboss.seam.framework.EntityQuery.getEntityManager(EntityQuery.java:153)
              at org.jboss.seam.framework.EntityQuery.validate(EntityQuery.java:37)
              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.seam.util.Reflections.invoke(Reflections.java:21)
              at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
              at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:38)
              at org.jboss.seam.util.Work.workInTransaction(Work.java:40)
              at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:32)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
              at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:166)
              at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)
              at com.digitalimpact.helloworld.session.PlanTableList_$$_javassist_1.validate(PlanTableList_$$_javassist_1.java)
              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.seam.util.Reflections.invoke(Reflections.java:21)
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:125)
              at org.jboss.seam.Component.callComponentMethod(Component.java:2082)
              at org.jboss.seam.Component.callCreateMethod(Component.java:2005)
              at org.jboss.seam.Component.newInstance(Component.java:1976)
              at org.jboss.seam.Component.getInstance(Component.java:1873)
              at org.jboss.seam.Component.getInstance(Component.java:1840)
              at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)
              at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50)
              at org.jboss.seam.el.SeamELResolver.resolveBase(SeamELResolver.java:166)
              at org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:53)
              at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
              at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
              at org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
              at org.jboss.el.parser.AstValue.getValue(AstValue.java:63)
              at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
              at org.jboss.seam.core.Expressions$1.getValue(Expressions.java:111)
              at org.jboss.seam.navigation.Param.getStringValueFromModel(Param.java:133)
              at org.jboss.seam.navigation.Pages.getStringValuesFromModel(Pages.java:690)
              at org.jboss.seam.ui.component.UISeamCommandBase.getUrl(UISeamCommandBase.java:51)
              at org.jboss.seam.ui.renderkit.LinkRendererBase.doEncodeBegin(LinkRendererBase.java:26)
              at org.jboss.seam.ui.util.cdk.RendererBase.encodeBegin(RendererBase.java:79)
              at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:788)
              at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:280)
              at org.richfaces.renderkit.html.ToolBarRendererBase.encodeChildren(ToolBarRendererBase.java:81)
              at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
              at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
              at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
              at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
              at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
              at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:216)
              at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
              at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
              at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
              at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
              at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
              at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
              at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
              at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
              at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
              at java.lang.Thread.run(Thread.java:619)
      Caused by: javax.naming.NameNotFoundException: helloworldEntityManagerFactory not bound
              at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
              at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
              at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
              at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
              at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
              at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
              at javax.naming.InitialContext.lookup(InitialContext.java:392)
              at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:243)
              ... 112 more
      



      I haven't been able to figure out why it says the EntityManagerFactory is not bound. The link between the persistence.xml and components.xml is there.


      Persistence.xml:


      <?xml version="1.0" encoding="UTF-8"?>
      <!-- Persistence deployment descriptor for dev profile -->
      <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="helloworld">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>java:/helloworldDatasource</jta-data-source>
            <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/>
               <property name="hibernate.hbm2ddl.auto" value="validate"/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.format_sql" value="true"/>
               <property name="jboss.entity.manager.factory.jndi.name" value="java:/helloworldEntityManagerFactory"/>
               <property name="hibernate.default_schema" value="DDOSCH"/>
            </properties>
         </persistence-unit>
          
      </persistence>
      



      Components.xml:


      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components"
                  xmlns:core="http://jboss.com/products/seam/core"
                  xmlns:persistence="http://jboss.com/products/seam/persistence"
                  xmlns:drools="http://jboss.com/products/seam/drools"
                  xmlns:bpm="http://jboss.com/products/seam/bpm"
                  xmlns:security="http://jboss.com/products/seam/security"
                  xmlns:mail="http://jboss.com/products/seam/mail"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation=
                      "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd 
                       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd 
                       http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.0.xsd
                       http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.0.xsd
                       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                       http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.0.xsd
                       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd">
      
         <core:init debug="true" jndi-pattern="helloworld/#{ejbName}/local"/>
           
         <core:manager concurrent-request-timeout="500" 
                       conversation-timeout="120000" 
                       conversation-id-parameter="cid"/>
          
         <persistence:managed-persistence-context name="entityManager"
                                           auto-create="true"
                            persistence-unit-jndi-name="java:/helloworldEntityManagerFactory"/>                          
      
         <drools:rule-base name="securityRules">
             <drools:rule-files>
                 <value>/security.drl</value>
             </drools:rule-files>
         </drools:rule-base>
      
         <security:identity security-rules="#{securityRules}" authenticate-method="#{authenticator.authenticate}" remember-me="true"/>
         
         <event type="org.jboss.seam.security.notLoggedIn">
             <action execute="#{redirect.captureCurrentView}"/>
         </event>
         <event type="org.jboss.seam.security.loginSuccessful">
             <action execute="#{redirect.returnToCapturedView}"/>
         </event>
         
         <mail:mail-session host="localhost" port="2525" username="test" password="test" />
              
         <!-- For use with jBPM pageflow or process management -->
         <!--  
         <bpm:jbpm>
            <bpm:process-definitions></bpm:process-definitions>
            <bpm:pageflow-definitions></bpm:pageflow-definitions>
         </bpm:jbpm>
         -->
            
      </components>
      



      Has anyone run into this problem before or does anyone see what is wrong?


      Thanks,
      Dan

        • 1. Re: EntityManagerFactory not found in JNDI helloworldEntityManagerFactory
          Dan Dosch Newbie

          I found the problem. When seam-gen created the entities for all tables and views in my database, it created one that had a problem. Even though the stack trace gave no indication that it may be the case, the entity for one of the views was causing the entire page to not work. Once I removed this entity and all references to it, everything began to work.


          • 2. Re: EntityManagerFactory not found in JNDI helloworldEntityManagerFactory
            Bradley Orner Newbie

            I am having the exact same problem.  I've been wrestling with this for a week now. I could really grow to love SEAM if I could get it to work. I've been through several of the tutorial, and the


            I've successfully gotten a shell SEAM project to generate and deploy using jboss tools in eclipse (basic login w/ demo/password works). I have also gotten a few of the seam-gen based examples to deploy. (But nothing worked out of the box. Ultimately, I reinstalled everything and was very careful to conform to jdk 1.5 (I was using 1.6, which might have caused some of my problems). After reinstalling, I was able to actually reverse engineer also (didn't work prior to reinstalling everything).


            My current state is the exact same as stated above:


            || java.lang.IllegalArgumentException: EntityManagerFactory not found in JNDI :||



            I have only used the SEAM project generator and reverse engineering from a database. So I have not modified any other files. I did an addtional experiment. Generated a seam project, then added a simple   entity using the New Seam Entity. Same error as above, with the same xml file declarations (other than the project name, of course).


            It's now been 7 straight days of wrestling with this, and I'm pretty flustered. Any help would be greatly appreciated.


            thanks,
            Brad


            • 3. Re: EntityManagerFactory not found in JNDI helloworldEntityManagerFactory
              Bradley Orner Newbie

              and to add my config info:


              components.xml:


              <persistence:managed-persistence-context name="entityManager"
                                                   auto-create="true"
                                    persistence-unit-jndi-name="java:/ridesEntityManagerFactory"/>



              persistence.xml:



              <persistence-unit name="rides">
                    <provider>org.hibernate.ejb.HibernatePersistence</provider>
                    <jta-data-source>java:/ridesDatasource</jta-data-source>
                    <properties>
                       <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
                       <property name="hibernate.hbm2ddl.auto" value="update"/>
                       <property name="hibernate.show_sql" value="true"/>
                       <property name="hibernate.format_sql" value="true"/>
                       <property name="jboss.entity.manager.factory.jndi.name" value="java:/ridesEntityManagerFactory"/>
                    </properties>
                 </persistence-unit>



              Is there anywhere else that a declaration needs to be made? I see in Chapter 8 (section 8.3.1. Using a Seam-managed persistence context with JPA) of the getting started manual (doc Link),  it shows the Entity Manager being injected, which in my case would look like


              @In EntityManager entityManager;
              


              I presume I'll need to update all the generated session.(entity)Home.java class defs that were generated by jbosstools during the reverse engineering with the em injection. I have not yet - is that what's causing the error?


              thanks again,
              Brad

              • 4. Re: EntityManagerFactory not found in JNDI helloworldEntityManagerFactory
                Dan Dosch Newbie

                Does JBoss throw any errors when initially starting?


                When I was having problems, JBoss would throw an error during startup (but still start successfully). This error referenced one of the views in my database. I removed the entity and all other references to this view and the error went away during JBoss startup.


                The stack trace when I tried to load the page gave no indication that this was the problem.

                • 5. Re: EntityManagerFactory not found in JNDI helloworldEntityManagerFactory
                  Bradley Orner Newbie

                  OK, I've made progress.


                  After poking around the net and doing lots of comparisons with the working booking example, I discovered that jboss-tools was not copying the (project)-ds.xml file to the server deploy directory.


                  So, looking at my server deploy directory:  jboss-4.2.2.GA/server/default/deploy,


                  I saw:


                  jboss-seam-booking.ear
                  jboss-seam-booking-ds.xml
                  rides-ear.ear



                  rides-ear.ear is my project deployment file. So I copied



                  (my-eclipse-workspace)\rides-ear\resources\rides-ds.xml




                  to the jboss deploy directory:



                  jboss-4.2.2.GA/server/default/deploy/:
                      jboss-seam-booking.ear
                      jboss-seam-booking-ds.xml
                      rides-ear.ear
                      rides-ds.xml



                  That has gotten me past my JNDI issue and all but one of the automatically generated 'xxxList' links are working! (woo hoo).


                  Jboss team question: Is the lack of xxx-ds.xml propagation to the server a jbosstools bug, or is this expected behavior?


                  thanks,
                  Brad

                  • 6. Re: EntityManagerFactory not found in JNDI helloworldEntityManagerFactory
                    Max Andersen Newbie

                    Jboss team question: Is the lack of xxx-ds.xml propagation to the server a jbosstools bug, or is this expected behavior?


                    If I understood the thread correctly you manually setup this project and did not use the Seam wizard ?


                    If you did use the Seam Wizard it should have configured it so the ear/war project gets deployed AND the -ds.xml file too.


                    If you do it manually in steps then you need to right click the -ds.xml file and say Deploy to server otherwise the publishing does not know that you want to deploy this concrete file which contains the datasource.

                    • 7. Re: EntityManagerFactory not found in JNDI helloworldEntityManagerFactory
                      Bradley Orner Newbie

                      Thanks, but I did use the wizard. I've only used joss tools wizards and followed doc. They generate very pretty source files.


                      I've punted on the jboss tools altogether for now and I'm trying to go with just the seam-gen approach per the reference doc. I have been completely unsuccessful at following the jbosstools doc that I've found


                      Jboss tools sets up the project structure differently from seam-gen (despite someone's post to the contrary). Since there is more doc based on the seam-gen approach, I'm going to try that avenue. Despite claims of simplicity, the laundry list of issues to configure non-seam elements (like trying to get any sort of unit test to work), figuring out exactly which jars to pull in and which to leave out, working through hibernate exceptions that don't tell me much, and the differences between the seam-gen doc and jboss tools layout is making my head spin.


                      So I'm going to try to just stick to the seam-gen approach as a last ditch effort in the hopes that I can actually build something. I'm giving this two more days. If I'm still stuck, SEAM is not an option, and I will have wasted an entire month on this.


                      • 8. Re: EntityManagerFactory not found in JNDI helloworldEntityManagerFactory
                        Bradley Orner Newbie

                        OK, so the crux of the issue appears to be twofold:


                        1) as Dan Doch posted above on 15. Mar 2008, if there's a problem with one of the generated entities, 'EntityManagerFactory not found in JNDI' error is posted. Debugging this situation was painful and not obvious. I ended up having to back off and start from ground zero (using seam gen instead, then coming back into a jboss tools generated environment). Don't ask me how I figured it out, because I'm not entirely sure.


                        2) jboss tools creates two persistence.xml files:
                           (project)/src/META-INF/persistence.xml
                           (project)-ejb/ejbModule/persistence.xml


                        The (project)/src version is empty, the (project-ejb) version is the one with all the good stuff in it. From what my experimentation showed, the empty one in (project)/src was the one being used, and consequently didn't refer to the (project)-ds.xml defined datasource.


                        Ultimately, copying the (project)-ejb version to (project)/src version got rid of the error. My quick read of the JPA spec alludes to the fact that both persistence.xml files should have been read, and since only one datasource definition exists, all should have been right with the world. Assuming I'm correct on this (which I may not be), then there's a bug in JBOSS AS (ie. both persistence.xml files should have been processed). Otherwise, it's a bug in the jboss tools persistence.xml generation (ie. only a single persistence.xml file should be maintained in the project).


                        Either way, both of these provide the SEAM team with an excellent area opportunity to improve both documentation and debuggability.

                        • 9. Re: EntityManagerFactory not found in JNDI helloworldEntityManagerFactory
                          Max Andersen Newbie

                          Bradley Orner wrote on Apr 06, 2008 05:44 PM:


                          Jboss tools sets up the project structure differently from seam-gen (despite someone's post to the contrary).



                          Yes - it uses a WTP project compatible structure.



                          Since there is more doc based on the seam-gen approach, I'm going to try that avenue. Despite claims of simplicity, the laundry list of issues to configure non-seam elements (like trying to get any sort of unit test to work),


                          What is it that does not work here ? TestNG tests are generated out-of-the-box - please report issues in jira if you find something not working.


                          • 10. Re: EntityManagerFactory not found in JNDI helloworldEntityManagerFactory
                            Max Andersen Newbie

                            Bradley Orner wrote on Apr 14, 2008 02:36 PM:


                            OK, so the crux of the issue appears to be twofold:

                            1) as Dan Doch posted above on 15. Mar 2008, if there's a problem with one of the generated entities, 'EntityManagerFactory not found in JNDI' error is posted. Debugging this situation was painful and not obvious. I ended up having to back off and start from ground zero (using seam gen instead, then coming back into a jboss tools generated environment). Don't ask me how I figured it out, because I'm not entirely sure.


                            Independent of tools, the best way of looking for why something is not found in JNDI is to look at any previous exceptions that should pretty precisly tell what caused the problem (e.g. some specific entity not being correct)



                            2) jboss tools creates two persistence.xml files:
                               (project)/src/META-INF/persistence.xml
                               (project)-ejb/ejbModule/persistence.xml

                            The (project)/src version is empty, the (project-ejb) version is the one with all the good stuff in it.


                            That is not generated by default. That only happens if you enable Eclipse Dali JPA in the wizard. There is a reason why we do not enable that by default.


                            We had some docs earlier that told you to enable it, but that should definitely not be the case anymore. If you read it in some recent docs then please point me to it so I can get that fixed.



                            version got rid of the error. My quick read of the JPA spec alludes to the fact that both persistence.xml files should have been read, and since only one datasource definition exists, all should have been right with the world. Assuming I'm correct on this (which I may not be), then there's a bug in JBOSS AS (ie. both persistence.xml files should have been processed).


                            It all depends on how it is packaged. There is normally only one persistence.xml per persistence unit, that persistence.xml can have multiple elements inside.



                            Otherwise, it's a bug in the jboss tools persistence.xml generation (ie. only a single persistence.xml file should be maintained in the project).


                            We only generate one.



                            Either way, both of these provide the SEAM team with an excellent area opportunity to improve both documentation and debuggability.


                            I agree that exceptions can be improved at JBoss AS/Seam/Hibernate level and until that happens we unfortunately can't do much. One thing I am trying to look into though is to figure out how to extract the previous thrown/logged exceptions in the logs so we can show it more directly to the user than having you to wade through all the logs.


                            • 11. Re: EntityManagerFactory not found in JNDI helloworldEntityManagerFactory
                              Alex McCarrier Newbie

                              I'm seeing this exact same problem with seam 2.0.2.GA and jboss 4.2.2.GA.  All generated with jboss-tools eclipse plugin.  I did notice initially I had to manually deploy k2-ds.xml to the server deploy dir by doing the right click deploy thing from within eclipse.  Even though the jndi-name was correct in source, it seemed to deploy a version that said k2Datasource ... only by changing the name to something else, then changing it back to k2 did it deploy correctly.


                              k2-ds.xml (deployed to jboss server/default/deploy)



                              <?xml version="1.0" encoding="UTF-8"?>
                              
                              <!DOCTYPE datasources
                                  PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
                                  "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
                                  
                              <datasources>
                                 
                                 <local-tx-datasource>
                                    <jndi-name>k2</jndi-name>
                                    <connection-url>jdbc:mysql://localhost:3306/k2</connection-url>
                                    <driver-class>com.mysql.jdbc.Driver</driver-class>
                                    <user-name>k2</user-name>
                                    <password>k2</password>
                              <!-- 
                                    <exception-sorter-class-name>
                                       org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
                                    </exception-sorter-class-name>
                                    <metadata>
                                       <type-mapping>mySQL</type-mapping>
                                    </metadata>
                              -->
                                 </local-tx-datasource>
                                  
                              </datasources>
                              





                              persistence.xml:




                              <?xml version="1.0" encoding="UTF-8"?>
                              <!-- Persistence deployment descriptor for dev profile -->
                              <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="k2">
                                    <provider>org.hibernate.ejb.HibernatePersistence</provider>
                                    <jta-data-source>java:/k2</jta-data-source>
                                    <properties>
                                       <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
                                       <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                                       <property name="hibernate.show_sql" value="true"/>
                                       <property name="hibernate.format_sql" value="true"/>
                                       <property name="jboss.entity.manager.factory.jndi.name" value="java:/EntityManagerFactories/k2"/>
                                    </properties>
                                 </persistence-unit>
                                  
                              </persistence>
                              





                              components.xml:



                              <?xml version="1.0" encoding="UTF-8"?>
                              <components xmlns="http://jboss.com/products/seam/components"
                                          xmlns:core="http://jboss.com/products/seam/core"
                                          xmlns:persistence="http://jboss.com/products/seam/persistence"
                                          xmlns:drools="http://jboss.com/products/seam/drools"
                                          xmlns:bpm="http://jboss.com/products/seam/bpm"
                                          xmlns:security="http://jboss.com/products/seam/security"
                                          xmlns:mail="http://jboss.com/products/seam/mail"
                                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                          xsi:schemaLocation=
                                              "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd 
                                               http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd 
                                               http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.0.xsd
                                               http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.0.xsd
                                               http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                                               http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.0.xsd
                                               http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd">
                              
                                 <core:init debug="true" jndi-pattern="@jndiPattern@"/>
                                   
                                 <core:manager concurrent-request-timeout="500" 
                                               conversation-timeout="120000" 
                                               conversation-id-parameter="cid"
                                               parent-conversation-id-parameter="pid"/>
                                  
                                 <persistence:managed-persistence-context name="entityManager"
                                                                   auto-create="true"
                                                    persistence-unit-jndi-name="java:/EntityManagerFactories/k2"/>                          
                              
                                 <drools:rule-base name="securityRules">
                                     <drools:rule-files>
                                         <value>/security.drl</value>
                                     </drools:rule-files>
                                 </drools:rule-base>
                              
                                 <security:identity security-rules="#{securityRules}" authenticate-method="#{authenticator.authenticate}" remember-me="true"/>
                                 
                                 <event type="org.jboss.seam.security.notLoggedIn">
                                     <action execute="#{redirect.captureCurrentView}"/>
                                 </event>
                                 <event type="org.jboss.seam.security.loginSuccessful">
                                     <action execute="#{redirect.returnToCapturedView}"/>
                                 </event>
                                 
                                 <mail:mail-session host="localhost" port="2525" username="test" password="test" />
                                      
                                 <!-- For use with jBPM pageflow or process management -->
                                 <!--  
                                 <bpm:jbpm>
                                    <bpm:process-definitions></bpm:process-definitions>
                                    <bpm:pageflow-definitions></bpm:pageflow-definitions>
                                 </bpm:jbpm>
                                 -->
                                    
                              </components>
                              
                              


                              • 12. Re: EntityManagerFactory not found in JNDI helloworldEntityManagerFactory
                                Alex McCarrier Newbie

                                One thing I'm noticing is that run on server in jboss tools (I'm using jboss tools version, not the eclipse jee servers panel) is not deploying persistence.xml or any file other than MANIFEST.MF in the ejb.jar file.

                                • 13. Re: EntityManagerFactory not found in JNDI helloworldEntityManagerFactory
                                  Alex McCarrier Newbie

                                  For some reason JBoss Tools isn't copying the META-INF contents to the deploy dir on the ejb project.  So waht I did was create a new folder called resources, copy the META-INF folder from ejbModule to resources, then modify .settings/org.eclipse.wst.common.component and add a line that looks like:


                                  <wb-resource deploy-path="/" source-path="/resources"/>
                                  



                                  That seemed to work.

                                  • 14. Re: EntityManagerFactory not found in JNDI helloworldEntityManagerFactory
                                    Alex Ricardo Newbie

                                    I had this same problem when i added more fields to a class that was already working. I added this:
                                         private String myField;
                                            public String getMyField() {
                                              return myField;
                                         }


                                         public void setMyField(String myField) {
                                              this.myField = myField;
                                         }


                                    After that i started having the mentioned exception, so i added the annotation      @Transient
                                    to the getter and got back on track:
                                         private String myField;


                                         @Transient
                                         public String getMyField() {
                                              return myField;
                                         }


                                         public void setMyField(String myField) {
                                              this.myField = myField;
                                         }


                                    I somebody knows a non obvious explanation please let us know.


                                    thks.