[jboss-user] [JBoss Seam] - NPE Problem with <s:convertEntity />, seems Entity manager i

gnevarez do-not-reply at jboss.com
Tue Nov 13 18:19:31 EST 2007


I have an error with a dropdown, it seems something is not correct about the entity manager or the Seam Managed Persistence Context (SMPC) , although I can get a log entry saying entities were retrieved from the database.

It's the booking example modified, some of the labels might be familiar.


I'm using Seam 2.0.0 and AS 4.2.2

Except from the view (registrounidad.xhtml)

  | <h:selectOneMenu id="idgrupo" value="#{unidad.idgrupo}" required="true">
  | 
  |               <s:selectItems value="#{gruposDisponibles}" var="grupo" label="#{grupo.nombre}" noSelectionLabel="Please select..."  />
  |               <s:convertEntity />
  |             </h:selectOneMenu>
  | 

persistance.xml

  | <?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="bookingDatabase">
  | 
  |       <provider>org.hibernate.ejb.HibernatePersistence</provider>
  | 
  |       <jta-data-source>java:/bookingDatasource</jta-data-source>
  | 
  |       <properties>
  | 
  |          <property name="hibernate.hbm2ddl.auto" value="update"/>
  | 
  | 		 <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
  | 
  |          <property name="hibernate.show_sql" value="true"/>
  | 
  |          <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
  | 
  |          <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
  |          <property name="jboss.entity.manager.factory.jndi.name" value="java:/unitsEntityManagerFactory"/>
  |       </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:security="http://jboss.com/products/seam/security"
  | 
  |             xmlns:transaction="http://jboss.com/products/seam/transaction"
  |             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/transaction http://jboss.com/products/seam/transaction-2.0.xsd
  | 
  |                  http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
  | 		 http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd ">
  | 
  | 
  | 
  |     <core:init jndi-pattern="@jndiPattern@" debug="true"/>
  | 
  | 
  | 
  |     <core:manager conversation-timeout="120000"
  | 
  |                   concurrent-request-timeout="500"
  | 
  |                   conversation-id-parameter="cid"/>
  | 
  |     <core:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/unitsEntityManagerFactory"/>.
  | 
  |     <transaction:ejb-transaction/>
  | 
  | 
  | 
  |     <security:identity authenticate-method="#{authenticator.authenticate}"/>
  | 
  | 
  | </components>
  | 

The Search Bean (UnidadSearchingAction.java)

  | package org.jboss.seam.example.booking;
  | 
  | import java.util.List;
  | 
  | import javax.ejb.Remove;
  | import javax.ejb.Stateful;
  | import javax.persistence.EntityManager;
  | import javax.persistence.PersistenceContext;
  | 
  | import org.jboss.seam.log.Log;
  | import org.jboss.seam.ScopeType;
  | import org.jboss.seam.annotations.Factory;
  | import org.jboss.seam.annotations.Name;
  | import org.jboss.seam.annotations.Scope;
  | import org.jboss.seam.annotations.Out;
  | import org.jboss.seam.annotations.In;
  | import org.jboss.seam.annotations.Logger;
  | import org.jboss.seam.annotations.datamodel.DataModel;
  | import org.jboss.seam.annotations.security.Restrict;
  | 
  | @Stateful
  | @Name("unidadSearch")
  | @Scope(ScopeType.SESSION)
  | @Restrict("#{identity.loggedIn}")
  | public class UnidadSearchingAction implements UnidadSearching
  | {
  |    
  |     @Logger
  |     Log log;
  | 
  |    @PersistenceContext
  |    private EntityManager entityManager;
  |    //private EntityManager em;
  |    
  |    private String searchString;
  |    private int pageSize = 10;
  |    private int page;
  |    
  |    @Out(required = false)
  |    public List<Grupo> gruposDisponibles;
  | 
  |    @DataModel
  |    private List<Unidad> unidades;
  |    
  |    public void find()
  |    {
  |       page = 0;
  |       queryUnidades();
  |    }
  |    public void nextPage()
  |    {
  |       page++;
  |       queryUnidades();
  |    }
  |    
  |    
  |    public List<Grupo> getGruposDisponibles() {
  | 	return gruposDisponibles; 
  |    }
  |     public void setGruposDisponibles(List<Grupo> gruposDisponibles) {
  | 	this.gruposDisponibles = gruposDisponibles;
  |     }
  |     
  |    @Factory("gruposDisponibles")
  |     public void comboGrupos()
  |    {
  | 	   log.info("Loading gruposDisponibles...");
  | 	   gruposDisponibles = entityManager.createQuery("select g from Grupo g  order by g.nombre")
  | 	               .getResultList();
  | 	   log.info("Size: " + gruposDisponibles.size());
  |    }
  |    
  |    private void queryUnidades()
  |    {
  | 	     unidades = entityManager.createQuery("select u from Unidad u where lower(u.etiqueta) like #{unidPattern} or lower(u.device) like #{unidPattern} or lower(u.placa) like #{unidPattern} order by u.etiqueta")
  | 	        .setMaxResults(pageSize)
  |             .setFirstResult( page * pageSize )
  |             .getResultList();
  |    }
  |    
  |    public boolean isNextPageAvailable()
  |    {
  |       return unidades!=null && unidades.size()==pageSize;
  |    }
  |    
  |    public int getPageSize() {
  |       return pageSize;
  |    }
  |    
  |    public void setPageSize(int pageSize) {
  |       this.pageSize = pageSize;
  |    }
  |    
  |    @Factory(value="unidPattern", scope=ScopeType.EVENT)
  |    public String getSearchPattern()
  |    {
  |       return searchString==null ? 
  |             "%" : '%' + searchString.toLowerCase().replace('*', '%') + '%';
  |    }
  |    
  |    public String getSearchString()
  |    {
  |       return searchString;
  |    }
  |    
  |    public void setSearchString(String searchString)
  |    {
  |       this.searchString = searchString;
  |    }
  |    
  |    @Remove
  |    public void destroy() {}
  | }
  | 

The Stack trace

  | 16:38:39,914 INFO  [UnidadSearchingAction] Loading gruposDisponibles...
  | 16:38:39,930 INFO  [STDOUT] Hibernate: select grupo0_.idgrupo as idgrupo51_, grupo0_.nombre as nombre51_, grupo0_.descripcion as descripc3_51_ from gpsgrupos grupo0_ order by grupo0_.nombre
  | 16:38:39,952 INFO  [UnidadSearchingAction] Size: 2
  | 16:38:39,972 ERROR [STDERR] Nov 13, 2007 4:38:39 PM com.sun.facelets.FaceletViewHandler handleRenderException
  | SEVERE: Error Rendering View[/registrounidad.xhtml]
  | java.lang.NullPointerException
  |         at org.jboss.seam.framework.EntityIdentifier.<init>(EntityIdentifier.java:15)
  |         at org.jboss.seam.ui.converter.EntityConverterStore.put(EntityConverterStore.java:60)
  |         at org.jboss.seam.ui.converter.EntityConverter.getAsString(EntityConverter.java:69)
  |         at org.jboss.seam.ui.converter.PrioritizableConverter.getAsString(PrioritizableConverter.java:67)
  |         at org.jboss.seam.ui.converter.ConverterChain.getAsString(ConverterChain.java:123)
  |         at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getFormattedValue(HtmlBasicRenderer.java:469)
  |         at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOption(MenuRenderer.java:502)
  |         at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(MenuRenderer.java:757)
  |         at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:811)
  |         at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:335)
  |         at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
  |         at org.jboss.seam.ui.util.cdk.RendererBase.renderChild(RendererBase.java:190)
  |         at org.jboss.seam.ui.util.cdk.RendererBase.renderChildren(RendererBase.java:166)
  |         at org.jboss.seam.ui.renderkit.ValidateAllRendererBase.doEncodeChildren(ValidateAllRendererBase.java:33)
  |         at org.jboss.seam.ui.util.cdk.RendererBase.encodeChildren(RendererBase.java:92)
  |         at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
  |         at org.jboss.seam.ui.util.cdk.RendererBase.renderChild(RendererBase.java:186)
  |         at org.jboss.seam.ui.util.cdk.RendererBase.renderChildren(RendererBase.java:166)
  |         at org.jboss.seam.ui.renderkit.DecorateRendererBase.doEncodeChildren(DecorateRendererBase.java:94)
  |         at org.jboss.seam.ui.util.cdk.RendererBase.encodeChildren(RendererBase.java:92)
  |         at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
  |         at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
  |         at javax.faces.render.Renderer.encodeChildren(Renderer.java:137)
  |         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:577)
  |         at org.ajax4jsf.framework.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
  |         at org.ajax4jsf.framework.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java:233)
  |         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:87)
  |         at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  |         at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:63)
  |         at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  |         at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:46)
  |         at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  |         at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:127)
  |         at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:277)
  |         at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:40)
  |         at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  |         at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:63)
  |         at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  |         at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:140)
  |         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.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)
  | 


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4104348#4104348

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4104348



More information about the jboss-user mailing list