1 2 Previous Next 16 Replies Latest reply on Nov 25, 2007 12:46 PM by demetrio812

    Seam, problem with EntityManager

    paata lominadze Master

      hi all,
      i have template using facelets, i have left menu and body pages, both of them has session beans, in the left menu bean i have generated richfaces HtmlPanelBarItem component, for leftmenu, in the body page i have richfaces tree componet generated from it's bean. all works fine i see PanelBar components in the left menu page and tree component on the body page, but then i tried to expand tree i got an exception, that in the left menu bean entitymanager is null :(, here is my example:
      1.faces-config.xml

       <managed-bean>
       <managed-bean-name>library</managed-bean-name> <managed-bean-class>com.liliko.billing.businesslayer.beans.common.Library</managed-bean-class>
       <managed-bean-scope>request</managed-bean-scope>
       </managed-bean>
      
       <managed-bean>
       <managed-bean-name>menu</managed-bean-name> <managed-bean-class>com.liliko.billing.businesslayer.beans.common.MenuBean</managed-bean-class>
       <managed-bean-scope>session</managed-bean-scope>
       </managed-bean>
      

      2. MenuBean.java
      @Name("menu")
      @Scope(ScopeType.SESSION)
      public class MenuBean {
      
       @In(value="#{entityManager}")
       private EntityManager entityManager;
       ............................................
      

      3. Library.java (body)
      @Name("library")
      @Scope(ScopeType.PAGE)
      public class Library implements TreeNode {
      
       @In(value="#{entityManager}")
       private EntityManager entityManager;
      ..................................
      

      exception occured when i tried to expand tree :(, why is the entitymanager null on this time ?
      error trace:

      Caused by: org.jboss.seam.RequiredException: In attribute requires non-null value: menu.#{entityManager}
       at org.jboss.seam.Component.getValueToInject(Component.java:1923)
       at org.jboss.seam.Component.injectAttributes(Component.java:1372)
       at org.jboss.seam.Component.inject(Component.java:1203)
      



      _________________
      Regards,
      Paata

        • 1. Re: Seam, problem with EntityManager
          Andreas Franke Apprentice

          if you have the following in components.xml

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


          you can use
          @In(create=true)
           private EntityManager entityManager;


          But one question. Why you have managed-bean stuff in faces-config.xml?
          This should be handelt from your annotations in your bean, I think!

          • 2. Re: Seam, problem with EntityManager
            Dennis Newbie

            You don't need

            @In(create=true)
            EntityManager entityManager;
            


            @In should be sufficent

            Greets

            • 3. Re: Seam, problem with EntityManager
              paata lominadze Master

               

              "g00se24" wrote:
              You don't need
              @In(create=true)
              EntityManager entityManager;
              


              @In should be sufficent

              Greets


              HI ALL,
              Thank you very much for your posts, i tried everything but myu problem still appears,
              problem is not on first time, i see tabpane and tree component generated from database, all works fine but when i tried to expand tree than an exception occured,


              i did not understand what happend :(, why got entitymanager null ?


              ________________
              Regards,
              Paata


              • 4. Re: Seam, problem with EntityManager
                paata lominadze Master

                if i remove generate tabpane from database and set simple string, everuthing works fine, tree also work.

                • 5. Re: Seam, problem with EntityManager
                  paata lominadze Master

                  can anybody help me ?

                  • 6. Re: Seam, problem with EntityManager
                    Chris Lowe Apprentice

                    Have you got an entry in persistence.xml that corresponds to your entity manager factory?

                    components.xml
                    
                     <core:managed-persistence-context name="entityManager"
                     auto-create="true"
                     persistence-unit-jndi-name="java:/dvdEntityManagerFactory"/>
                    
                    
                    persistence.xml
                    <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="dvdDatabase">
                     <provider>org.hibernate.ejb.HibernatePersistence</provider>
                     <jta-data-source>java:/dvdDatasource</jta-data-source>
                     <properties>
                     <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                     <property name="hibernate.cache.use_query_cache" value="true"/>
                     <property name="hibernate.show_sql" value="true"/>
                    
                     <property name="hibernate.cache.provider_class"
                     value="org.hibernate.cache.HashtableCacheProvider"/>
                    
                     <!-- use a file system based index -->
                     <property name="hibernate.search.default.directory_provider"
                     value="org.hibernate.search.store.FSDirectoryProvider"/>
                     <!-- directory where the indexes will be stored -->
                     <property name="hibernate.search.default.indexBase" value="./dvdindexes"/>
                     <!-- Not needed with HA 3.3 -->
                     <property name="hibernate.ejb.event.post-insert" value="org.hibernate.search.event.FullTextIndexEventListener"/>
                     <property name="hibernate.ejb.event.post-update" value="org.hibernate.search.event.FullTextIndexEventListener"/>
                     <property name="hibernate.ejb.event.post-delete" value="org.hibernate.search.event.FullTextIndexEventListener"/>
                    
                     <property name="jboss.entity.manager.factory.jndi.name"
                     value="java:/dvdEntityManagerFactory" />
                     </properties>
                     </persistence-unit>
                    </persistence>
                    



                    One other potential trap is that I have just upgraded from Seam 1.2.1 to 2.0b1 and "managed-persistence-context" has been moved from namespace core to persistence. If this is the case, then don't forget to add the persistence namespace to your XML namespace config:

                    xmlns:persistence="http://jboss.com/products/seam/persistence"

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

                    See DVD store example for complete code.

                    • 7. Re: Seam, problem with EntityManager
                      Jan Koops Newbie

                       

                      One other potential trap is that I have just upgraded from Seam 1.2.1 to 2.0b1 and "managed-persistence-context" has been moved from namespace core to persistence. If this is the case, then don't forget to add the persistence namespace to your XML namespace config:

                      xmlns:persistence="http://jboss.com/products/seam/persistence"

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


                      Please add this to the seam2migration.txt, I spent one day on this.

                      • 8. Re: Seam, problem with EntityManager
                        paata lominadze Master

                        hi lowecg2004,
                        first of all thank you for your post, i tried all versions of seam and jboss application server,
                        is this so difficult that use seam and richfaces together ???
                        i already tried this for a week but could not resolve :(
                        environment :

                        1. JBoss AS 4.2.0GA
                        2. Seam 2.0.0.BETA1
                        3. Richfaces 3.0.1
                        4.ajax4jsf 1.1.1



                        here is my example simple dynamic tree generation into seam component :
                        1.MenuBean.java (Seam Component)

                        @Name("menu")
                        @Scope(ScopeType.SESSION)
                        public class MenuBean{
                        
                         @In
                         private EntityManager entityManager;
                        
                         private HtmlPanelBar bar = new HtmlPanelBar();
                         public MenuBean() {
                         }
                        
                         public HtmlPanelBar getBar() {
                         if (bar!=null && bar.getChildren()!=null) {
                         bar.getChildren().clear();
                         }
                        
                         ArrayList<Menu> arraylist = (ArrayList<Menu>)entityManager.createNamedQuery("Menu.findAll").getResultList();
                         for (Menu elem : arraylist) {
                         HtmlPanelBarItem item= new HtmlPanelBarItem();
                         item.setLabel("Blaaaa");
                        
                         Library library = new Library();
                         HtmlTree tree = new HtmlTree();
                         tree.setStyle("width:150px");
                         tree.setValue(library.getData());
                         tree.setVar("item");
                         tree.setNodeFace(library.getType());
                        
                        
                         Iterator<Artist> itArtists = library.getArtists().values().iterator();
                         while (itArtists.hasNext()) {
                         Artist artist = (Artist)itArtists.next();
                        
                         HtmlTreeNode artistNode = new HtmlTreeNode();
                         artistNode.setType("artist");
                         HtmlOutputText artistText = new HtmlOutputText();
                         artistText.setValue(artist.getName());
                        
                         Iterator<Album> itAlbums = artist.getAlbums();
                         while (itAlbums.hasNext()) {
                         Album album = (Album) itAlbums.next();
                        
                         HtmlTreeNode albumNode = new HtmlTreeNode();
                         albumNode.setType("album");
                         HtmlOutputText albumText = new HtmlOutputText();
                         albumText.setValue(album.getTitle());
                        
                         Iterator<Song> itSongs = album.getSongs();
                         while (itSongs.hasNext()) {
                         Song song = (Song) itSongs.next();
                        
                         HtmlTreeNode songNode = new HtmlTreeNode();
                         songNode.setType("song");
                         HtmlOutputText songText = new HtmlOutputText();
                         songText.setValue(song.getTitle());
                        
                         tree.getChildren().add(songNode);
                         }
                         tree.getChildren().add(albumNode);
                         tree.getChildren().add(artistNode);
                         item.getChildren().add(tree);
                         bar.getChildren().add(item);
                         }
                         }
                         }
                         return bar;
                         }
                         public void setBar(HtmlPanelBar bar) {
                         this.bar = bar;
                         }
                        }
                        

                        1.Home.xhtml (Presentation Layer)
                         <ui:define name="body">
                        
                         <h:messages globalOnly="true" styleClass="message"/>
                         <h:form id="bodyForm">
                         <rich:panel>
                         <f:facet name="header">Welcome!</f:facet>
                         <p>This empty shell application includes:</p>
                         <ul>
                         <li>Ant build script</li>
                         <li>Deployment to JBoss AS</li>
                         <li>Integration testing using TestNG and JBoss Embeddable EJB3</li>
                         <li>EJB 3.0 Seam components</li>
                         <li>Templated Facelets views</li>
                         <li>HSQL (or MySQL) Datasource</li>
                         <li>Default CSS stylesheet</li>
                         <li>Internationalization support</li>
                         </ul>
                         <rich:panelBar binding="#{menu.bar}" width="500" height="600">
                         </rich:panelBar>
                         </rich:panel>
                         </h:form>
                         </ui:define>
                        


                        i always get this error :
                        Caused by: org.jboss.seam.RequiredException: In attribute requires non-null value: menu.entityManager
                         at org.jboss.seam.Component.getValueToInject(Component.java:2042)
                         at org.jboss.seam.Component.injectAttributes(Component.java:1481)
                         at org.jboss.seam.Component.inject(Component.java:1302)
                        


                        i tried to find something into seam code but i could not find anything for this issue,
                        you told me about configurations lowecg200, here is my configurations :

                        1.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: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/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="@debug@" jndi-pattern="@jndiPattern@"/>
                        
                         <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:/NewBillingEntityManagerFactory"/>
                        
                         <drools:rule-base name="securityRules">
                         <drools:rule-files>
                         <value>/security.drl</value>
                         </drools:rule-files>
                         </drools:rule-base>
                        
                         <security:identity authenticate-method="#{authenticator.authenticate}"
                         security-rules="#{securityRules}"/>
                        
                         <event type="org.jboss.seam.notLoggedIn">
                         <action expression="#{redirect.captureCurrentView}"/>
                         </event>
                         <event type="org.jboss.seam.postAuthenticate">
                         <action expression="#{redirect.returnToCapturedView}"/>
                         </event>
                         <mail:mail-session host="localhost" port="2525" username="test" password="test" />
                        </components>
                        


                        here is managed-persistence-context defined
                        2.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="NewBilling">
                         <provider>org.hibernate.ejb.HibernatePersistence</provider>
                         <jta-data-source>java:/NewBillingDatasource</jta-data-source>
                         <properties>
                         <property name="hibernate.hbm2ddl.auto" value="validate"/>
                         <property name="hibernate.cache.use_query_cache" value="true"/>
                         <property name="hibernate.show_sql" value="true"/>
                         <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
                        
                         <!-- use a file system based index -->
                         <property name="hibernate.search.default.directory_provider"
                         value="org.hibernate.search.store.FSDirectoryProvider"/>
                         <!-- directory where the indexes will be stored -->
                         <property name="hibernate.search.default.indexBase" value="./dvdindexes"/>
                         <!-- Not needed with HA 3.3 -->
                         <property name="hibernate.ejb.event.post-insert" value="org.hibernate.search.event.FullTextIndexEventListener"/>
                         <property name="hibernate.ejb.event.post-update" value="org.hibernate.search.event.FullTextIndexEventListener"/>
                         <property name="hibernate.ejb.event.post-delete" value="org.hibernate.search.event.FullTextIndexEventListener"/>
                        
                        
                         <property name="jboss.entity.manager.factory.jndi.name" value="java:/NewBillingEntityManagerFactory"/>
                        
                         <property name="hibernate.default_schema" value="JITS"/>
                         </properties>
                         </persistence-unit>
                        </persistence>
                        

                        also here is jndi.name defined correctly.
                        i also saw dvd example and i could not find difference into configurations.

                        have you ever tried to use richfaces and seam together ??

                        and i have one another question also, if i have one ejb interface and seam components which is also bean for component (for example richfaces treenode bean) how i can call ejb component ?? @EJB does not work, i like separated logic : business layer - presentation layer, how i can call ejb component ?


                        Any idea will be appreciated.

                        ________________________
                        Regards,
                        Paata.

                        • 9. Re: Seam, problem with EntityManager
                          Chris Lowe Apprentice

                          Hello Paata,

                          Your code and persistence.xml/components.xml config look okay to me. Do you have an entry in your startup logs that looks like the following?

                          16:53:36,554 INFO [Component] Component: entityManager, scope: CONVERSATION, type: JAVA_BEAN, class: org.jboss.seam.persistence.ManagedPersistenceContext


                          If your entityManager was successfully created then you'll have an entry like the one above. Otherwise, you'll not. This will at least tell us if there is a config issue or not.

                          Have you still got the managed-bean config from your original post hanging around?

                          I'm using RichFaces without any problems.

                          As for your EJB3 question - I don't know the answer to this, hopefully someone else can help you here. Maybe you could try making your Seam POJO into a SFSB? As a SFSB you could also try @PersistenceContext for getting at your entityManager?

                          Could you post your web.xml and faces-config.xml?

                          Regards,

                          Chris.

                          • 10. Re: Seam, problem with EntityManager
                            paata lominadze Master

                            HI lowecg2004, i saw log and i found this :

                            04:03:56,515 INFO [Component] Component: org.jboss.seam.core.init, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.Init
                            04:03:56,559 INFO [Initialization] Installing components...
                            04:03:56,593 INFO [Component] Component: authenticator, scope: EVENT, type: JAVA_BEAN, class: action.com.liliko.billing.businesslayer.beans.session.Authenticator
                            04:03:56,635 INFO [Component] Component: entityManager, scope: CONVERSATION, type: JAVA_BEAN, class: org.jboss.seam.persistence.ManagedPersistenceContext
                            04:03:56,653 INFO [Component] Component: menu, scope: SESSION, type: JAVA_BEAN, class: model.MenuBean
                            

                            entity manager exist,
                            here is my web.xml :
                            <?xml version="1.0" ?>
                            <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
                             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
                             version="2.4">
                            
                             <!-- Ajax4jsf -->
                            
                             <context-param>
                             <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
                             <param-value>com.sun.facelets.FaceletViewHandler</param-value>
                             </context-param>
                            
                             <context-param>
                             <param-name>org.ajax4jsf.SKIN</param-name>
                             <param-value>blueSky</param-value>
                             </context-param>
                            
                             <!-- Seam -->
                            
                             <listener>
                             <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
                             </listener>
                            
                             <filter>
                             <filter-name>Seam Filter</filter-name>
                             <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
                             </filter>
                            
                             <filter-mapping>
                             <filter-name>Seam Filter</filter-name>
                             <url-pattern>/*</url-pattern>
                             </filter-mapping>
                            
                             <servlet>
                             <servlet-name>Seam Resource Servlet</servlet-name>
                             <servlet-class>org.jboss.seam.servlet.ResourceServlet</servlet-class>
                             </servlet>
                            
                             <servlet-mapping>
                             <servlet-name>Seam Resource Servlet</servlet-name>
                             <url-pattern>/seam/resource/*</url-pattern>
                             </servlet-mapping>
                            
                             <!-- Facelets development mode (disable in production) -->
                            
                             <context-param>
                             <param-name>facelets.DEVELOPMENT</param-name>
                             <param-value>true</param-value>
                             </context-param>
                            
                             <!-- JSF -->
                            
                             <context-param>
                             <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
                             <param-value>.xhtml</param-value>
                             </context-param>
                            
                             <servlet>
                             <servlet-name>Faces Servlet</servlet-name>
                             <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
                             <load-on-startup>1</load-on-startup>
                             </servlet>
                            
                             <servlet-mapping>
                             <servlet-name>Faces Servlet</servlet-name>
                             <url-pattern>*.seam</url-pattern>
                             </servlet-mapping>
                            
                             <security-constraint>
                             <display-name>Restrict raw XHTML Documents</display-name>
                             <web-resource-collection>
                             <web-resource-name>XHTML</web-resource-name>
                             <url-pattern>*.xhtml</url-pattern>
                             </web-resource-collection>
                             <auth-constraint>
                             <role-name>NONE</role-name>
                             </auth-constraint>
                             </security-constraint>
                            
                            </web-app>
                            
                            

                            and my faces-config.xml
                            <?xml version='1.0' encoding='UTF-8'?>
                            <faces-config version="1.2"
                             xmlns="http://java.sun.com/xml/ns/javaee"
                             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
                            
                             <application>
                             <locale-config>
                             <default-locale>en</default-locale>
                             <supported-locale>en</supported-locale>
                             <supported-locale>ka</supported-locale>
                             <supported-locale>de</supported-locale>
                             <supported-locale>fr</supported-locale>
                             </locale-config>
                             <message-bundle>messages</message-bundle>
                             </application>
                            
                             <application>
                             <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
                             </application>
                            </faces-config>
                            
                            


                            is this configuration files incorrect ?
                            i use seam gen fro project creation, i don't understand why this not working :(


                            _____________
                            Regards,
                            Paata



                            • 11. Re: Seam, problem with EntityManager
                              paata lominadze Master

                              this files identical with dvd example files,
                              why this is not working :(,

                              • 12. Re: Seam, problem with EntityManager
                                paata lominadze Master

                                i found example which load data from xml file, i use seam 2.0 beta version and richfaces with ajax4jsf, here is another problem, i tried to load xml file into seam component like this :

                                InputSource ins1 = new InputSource(getClass().getResourceAsStream("data.xml"));
                                Digester digester = new Digester();
                                 Rule rule = new Rule();
                                 final List rulesList = new ArrayList(1);
                                 rulesList.add(rule);
                                
                                 RulesBase rulesBase = new RulesBase() {
                                 protected List lookup(String namespace, String name) {
                                 return rulesList;
                                 }
                                 };
                                 digester.setRules(rulesBase);
                                 digester.setNamespaceAware(true);
                                 digester.parse(ins1);
                                


                                but i got an error :
                                java.net.MalformedURLException
                                

                                i have this fine into my ejb jar file, but i can't read it :(
                                is there any incorrect ?


                                __________________
                                Regards,
                                Paata.


                                • 13. Re: Seam, problem with EntityManager
                                  Juan Rodriguez Newbie


                                  grdzeli_kaci:

                                  Could you fix the problem?

                                  Could you post the code fixed

                                  Regards


                                  Jaime

                                  • 14. Re: Seam, problem with EntityManager
                                    Mick Knutson Newbie

                                     

                                    "jrodri" wrote:

                                    grdzeli_kaci:

                                    Could you fix the problem?

                                    Could you post the code fixed

                                    Regards


                                    Jaime

                                    Any update you can post here please?

                                    1 2 Previous Next