1 2 Previous Next 17 Replies Latest reply on Mar 16, 2010 12:50 AM by bsgcic

    Using new matchingEntityConverter class. Getting java.lang.ClassCastException

    bsgcic

      My background: I am new to both Seam and Java though I've been studying them with great enthusiasm and effort for a significant while. My background is in the old ASP vbscript world (MS Access db). Instead of going .Net, I am developing with Java/seam/postgres.


      System environment: Java (latest)/Seam (2.1.2.GA)/Postgresql (8.4)/Jboss AS (5.1.0.GA)/Eclipse (3.4.2) with Seam Tools (latest) on a Windows Server 2003 native Japanese machine. Jboss default server deployed with postgres-ds.xml and postgresql-persistence-service.xml rather than hsqldb-ds.xml and hsqldb-persistence-service.xml.


      I have been stumped with getting the s:convertEntity working with a h:selectOneMenu control which has had me pouring through tons of blogs, community posts, etc. for about two full weeks now. Ugh!


      I found Christian Bauer's post of his new matchingEntityConverter class yesterday and am now trying to use that instead of s:convertEntity.


      matchingEntityConvert can be found at the following links:


      relation.to/Bloggers/DropdownsInJSFValidatingTheSelectedValue


      Documentation/DropdownBoxesWithEntitiesAndPSageScope


      Some initial questions before getting into the current error that I am getting:


      1. I believe that I learned from one or more postings that s:convertEntity would work with h:selectOneMenu but not multi-select controls. For example, the following link mentions that Unfortunately, Seam's convertEnum can't handle multi selects yet. in a discussion of s:convertEnum on a h:selectManyCheckbox control. Link.


      Question: Is the matchingEntityConverter class expected to work with multi-select controls as well as single select controls?


      2. I have seen postings indicating that Seam assumes that the name of the parameter assigned @id in entities is called id and that naming it id is important for some classes such as s:convertEntity. Is this really true? I had named given them a different name (though in my entities and tables for testing the s:convertEntity functionality, I am using the name id to keep it simple). Should I change all of the @id parameters to id or does it not matter?


      3. I assumed that the following are the classes needed by the matchingEntityConvert class. Is this correct?
      In particular, java.util. instead of org.hibernate.mapping. for Collection and Set. Also org.jboss.seam.ui. instead of org.hibernate.loader.entity. for AbstractEntityLoader.


      java.beans.Introspector, java.beans.PropertyDescriptor, java.io.Serializable, java.util.Collection, java.util.HashSet, java.util.Set, javax.faces.component.UIComponent, javax.faces.context.FacesContext, javax.faces.convert.ConverterException, org.jboss.seam.annotations.Install, org.jboss.seam.annotations.Name, org.jboss.seam.annotations.faces.Converter, org.jboss.seam.annotations.intercept.BypassInterceptors, org.jboss.seam.annotations.Scope, org.jboss.seam.annotations.Transactional, org.jboss.seam.ui.AbstractEntityLoader, org.jboss.seam.ScopeType



      Below is the error information that I am getting:


      Stack Trace:


      
      08:59:19,671 SEVERE [viewhandler] Error Rendering View[/person04tst03.xhtml]
      java.lang.ClassCastException: org.jboss.seam.ui.JpaEntityLoader_$$_javassist_seam_8 cannot be cast to org.jboss.seam.ui.AbstractEntityLoader
           at org.jboss.seam.ui.AbstractEntityLoader.instance(AbstractEntityLoader.java:55)
           at com.mysite.conversation.MatchingEntityConverter.getEntityLoader(MatchingEntityConverter.java:76)
           at com.mysite.conversation.MatchingEntityConverter.getAsString(MatchingEntityConverter.java:95)
           at org.jboss.seam.ui.converter.PrioritizableConverter.getAsString(PrioritizableConverter.java:67)
           at org.jboss.seam.ui.converter.ConverterChain.getAsString(ConverterChain.java:126)
           at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getFormattedValue(HtmlBasicRenderer.java:448)
           at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOption(MenuRenderer.java:480)
           at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(MenuRenderer.java:772)
           at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:832)
           at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:280)
           at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861)
           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:837)
           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:152)
           at org.jboss.seam.ui.util.cdk.RendererBase.encodeChildren(RendererBase.java:92)
           at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
           at javax.faces.render.Renderer.encodeChildren(Renderer.java:148)
           at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
           at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
           at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
           at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
           at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
           at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
           at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
           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.IdentityFilter.doFilter(IdentityFilter.java:40)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
           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:178)
           at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
           at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
           at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
           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:235)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
           at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
           at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
           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:158)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
           at java.lang.Thread.run(Thread.java:619)
      
      



      Also the following Warning:


      
      08:59:19,656 WARN  [AjaxRendererUtils] AJAX Status component not found for AjaxComponent with id j_id140
      08:59:19,812 WARN  [AjaxRendererUtils] AJAX Status component not found for AjaxComponent with id j_id140
      
      



      I put in the following package:


      package com.mysite.conversation;



      Components.xml:


      
      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components"
                  xmlns:bpm="http://jboss.com/products/seam/bpm"
                  xmlns:core="http://jboss.com/products/seam/core"
                  xmlns:drools="http://jboss.com/products/seam/drools"
                  xmlns:framework="http://jboss.com/products/seam/framework"
                  xmlns:mail="http://jboss.com/products/seam/mail"
                  xmlns:persistence="http://jboss.com/products/seam/persistence"
                  xmlns:security="http://jboss.com/products/seam/security"
                  xmlns:transaction="http://jboss.com/products/seam/transaction"
                  xmlns:web="http://jboss.com/products/seam/web"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation=
                      "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
                       http://jboss.com/products/seam/framework http://jboss.com/products/seam/framework-2.1.xsd
                       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd
                       http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd
                       http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
                       http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsd
                       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                       http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
                       http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.1.xsd
                       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">
      
          <core:init jndi-pattern="@jndiPattern@" debug="true" distributable="false"/>
      
          <core:manager 
                    conversation-timeout="120000"
                          concurrent-request-timeout="500"
                          conversation-id-parameter="cid"
                />
      
          <transaction:ejb-transaction/>
                
                <persistence:managed-persistence-context name="entityManager" 
                          persistence-unit-jndi-name="java:/com-mysiteEntityManagerFactory"
                />
                
                     <!-- framework:entity-home name="catGenderHome" entity-class="com.mysite.entity.CatGender" / -->
                     
                <!-- factory name="catGender" value="#{catGenderHome.instance}" / -->
                
                
                <component name="identifierMatchingEntityConverter"
                          class="com.mysite.conversation.MatchingEntityConverter"
                >
                     <property name="match">id</property> <!-- That's actually the default property we'd use for comparison-->
                </component>
                
                
          <security:identity authenticate-method="#{authenticator.authenticate}"/>
      
      </components>
      
      



      View: person04tst03.xhtml


      
      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition
           xmlns="http://www.w3.org/1999/xhtml"
           xmlns:ui="http://java.sun.com/jsf/facelets"
           xmlns:h="http://java.sun.com/jsf/html"
           xmlns:f="http://java.sun.com/jsf/core"
           xmlns:s="http://jboss.com/products/seam/taglib"
           xmlns:rich="http://richfaces.org/rich"
           xmlns:a="http://richfaces.org/a4j"
           template="/layout/defaultATemplate.xhtml"
      >
      
      ... (bunch of html) ...
      
      <ui:define name="content">
           
           <div class="section"><!-- RandomRef_ALSog -->
                <h1>person04Create</h1>
           </div><!-- class="section" --><!-- RandomRef_ALSog -->
           
           <div class="section"><!-- RandomRef_kjADe -->
           
                <div class="entry errors">
                     <h:messages id="messages" globalOnly="true"/>
                </div><!-- class="entry errors" -->
                
                <h:form id="person04CreationForm">
                     <fieldset><!-- RandomRef_BSEgk -->
                          
                          <s:decorate id="usernameDecorate" template="layout/edit.xhtml">
                               <ui:define name="label">Username:</ui:define>
                               <h:inputText id="username" value="#{person04.username}" required="true">
                                    <a:support id="onblur" event="onblur" reRender="usernameDecorate"/>
                               </h:inputText><!-- id="username" -->
                          </s:decorate><!-- id="usernameDecorate" -->
                          
                          <s:decorate id="nameDecorate" template="layout/edit.xhtml">
                               <ui:define name="label">Real Name:</ui:define>
                               <h:inputText id="name" value="#{person04.name}" required="true">
                                    <a:support id="onblur" event="onblur" reRender="nameDecorate"/>
                               </h:inputText><!-- id="name" -->
                          </s:decorate><!-- id="nameDecorate" -->
                          
                          <s:decorate id="passwordDecorate" template="layout/edit.xhtml">
                               <ui:define name="label">Password:</ui:define>
                               <h:inputSecret id="password" value="#{person04.password}" required="true"/>
                          </s:decorate><!-- id="passwordDecorate" -->
                          
                          <s:decorate id="verifyDecorate" template="layout/edit.xhtml">
                               <ui:define name="label">Verify Password:</ui:define>
                               <h:inputSecret id="verify" value="#{person04Create.verify}" required="true"/>
                          </s:decorate><!-- id="verifyDecorate" -->
                          
                          <s:decorate id="firstNameDecorate" template="layout/edit.xhtml">
                               <ui:define name="label">First Name:</ui:define>
                               <h:inputText id="firstName" value="#{person04.firstName}" required="true">
                                    <a:support id="onblur" event="onblur" reRender="firstNameDecorate"/>
                               </h:inputText><!-- id="firstName" -->
                          </s:decorate><!-- id="firstNameDecorate" -->
                          
                          <s:decorate id="lastNameDecorate" template="layout/edit.xhtml">
                               <ui:define name="label">Last Name:</ui:define>
                               <h:inputText id="lastName" value="#{person04.lastName}" required="true">
                                    <a:support id="onblur" event="onblur" reRender="lastNameDecorate"/>
                               </h:inputText><!-- id="lastName" -->
                          </s:decorate><!-- id="lastNameDecorate" -->
                          
                          
                          <s:decorate id="country01Decorate" template="layout/edit.xhtml">
                               <ui:define name="label">Country01:</ui:define>
                               
                               
                               <!-- h:inputText id="country01" value="# {person04.country01.id}" required="true">
                                    <a:support id="onblur" event="onblur" reRender="country01Decorate"/>
                               </h:inputText --><!-- id="country01" -->
                               
                               
                               <h:selectOneMenu value="#{person04.country01}" required="true"
                                         converter="#{identifierMatchingEntityConverter}">
                                         
                                    <s:selectItems value="#{country01s}" 
                                              var="country01Var"
                                              label="#{country01Var.name}"
                                              noSelectionLabel="Please Select..."/>
                                              
                                    <a:support event="onchange" reRender="country01Decorate" status="globalStatus"/>
                                    
                                    <!-- s:convertEntity / -->
                                    
                               </h:selectOneMenu>
                               
                               
                          </s:decorate><!-- id="country01Decorate" -->
                          
                          
                          <div class="buttonBox">
                               <h:commandButton id="person04Create" value="Person04Create" action="#{person04Create.register}"/>
                               &#160;
                               <s:button id="cancel" value="Cancel" view="/home.xhtml"/>
                          </div><!-- class="buttonBox" -->
                          
                     </fieldset><!-- RandomRef_BSEgk -->
                </h:form><!-- id="person04CreationForm" -->
                
           </div><!-- RandomRef_kjADe -->
           
      </ui:define><!-- content -->
      
      
      </ui:composition>
      
      
      




      PLEASE NOTE: IN THE ENTITY CLASSES: TABLE, COLUMN AND JOINCOLUMN NAMES ARE ENCLODED IN BACKTICKS IN ORDER TO SUCCESSFULLY INTERACT WITH POSTGRESQL.
      HOWEVER, I CHANGED THEM TO FORWARD TICKS IN THIS POST AS THEY WERE CAUSING FORMATTING ERRORS IN THIS SEAMFRAMEWORK.ORG FORUM POSTING FORM




      Enitity: Person04.java


      
      package com.mysite.entity;
      
      import static org.jboss.seam.ScopeType.SESSION;
      
      import java.io.Serializable;
      
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import javax.persistence.GenerationType;
      import javax.persistence.Id;
      import javax.persistence.JoinColumn;
      import javax.persistence.ManyToOne;
      import javax.persistence.SequenceGenerator;
      import javax.persistence.Table;
      
      import org.hibernate.validator.Length;
      import org.hibernate.validator.NotNull;
      import org.hibernate.validator.Pattern;
      
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      
      @Entity
      @Name("person04")
      @Scope(SESSION)
      @Table(name="'person04'")
      public class Person04 implements Serializable
      {
           
           private String username;
           private String password;
           private String name;
           private Long id;
           private String firstName;
           private String lastName;
           
           private Country01 country01;
           
           public Person04(String name, String password, String username)
           {
                this.name = name;
                this.password = password;
                this.username = username;
           }
           
           public Person04() {}
           
           
           @NotNull
           @Length(max=100)
           @Column(name="'name'")
           public String getName()
           {
                return name;
           }
           public void setName(String name)
           {
                this.name = name;
           }
           
           @NotNull
           @Length(min=5, max=15)
           @Column(name="'password'")
           public String getPassword()
           {
                return password;
           }
           public void setPassword(String password)
           {
                this.password = password;
           }
           
           @Length(min=4, max=15)
           @Pattern(regex="^\\w*$", message="not a valid username")
           @Column(name="'username'")
           public String getUsername()
           {
                return username;
           }
           public void setUsername(String username)
           {
                this.username = username;
           }
           
           
           @Id
           @NotNull
           @SequenceGenerator(name="person04_id_seqIdentifier", sequenceName="person04_id_seq", allocationSize=1)     
           @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="person04_id_seqIdentifier")
           @Column(name="'id'", unique=true, columnDefinition="bigserial")
           public Long getId()
           {
                return id;
           }
           public void setId(Long id)
           {
                this.id = id;
           }
           
           
           @NotNull
           @Column(name="'firstName'")
           public String getFirstName()
           {
                return firstName;
           }
           
           public void setFirstName(String firstName)
           {
                this.firstName = firstName;
           }
           
           
           @NotNull
           @Column(name="'lastName'")
           public String getLastName()
           {
                return lastName;
           }
           
           public void setLastName(String lastName)
           {
                this.lastName = lastName;
           }
           
           
           @ManyToOne
           @JoinColumn(name="'country01Id'")
           public Country01 getCountry01()
           {
                return country01;
           }
           
           public void setCountry01(Country01 country01)
           {
                this.country01 = country01;
           }
           
           
           @Override
           public String toString()
           {
                return "Person04(" +
                          username +
                          ")";
           }
           
      }
      
      





      Entity: Country01.java


      
      package com.mysite.entity;
      
      import static org.jboss.seam.ScopeType.SESSION;
      
      import java.io.Serializable;
      
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import javax.persistence.GenerationType;
      import javax.persistence.Id;
      import javax.persistence.SequenceGenerator;
      import javax.persistence.Table;
      
      import org.hibernate.validator.Length;
      import org.hibernate.validator.NotNull;
      
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      
      @Entity
      @Name("country01")
      @Scope(SESSION)
      @Table(name="'country01'")
      public class Country01 implements Serializable
      {
           
           private Long id;
           private String name;
           
           
           public Country01(String name)
           {
                this.name = name;
           }
           
           public Country01() {}
           
           
           @Id
           @NotNull
           @SequenceGenerator(name="country01_id_seqIdentifier", sequenceName="country01_id_seq", allocationSize=1)     
           @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="country01_id_seqIdentifier")
           @Column(name="'id'", unique=true, columnDefinition="bigserial")
           public Long getId()
           {
                return id;
           }
           public void setId(Long id)
           {
                this.id = id;
           }
           
           
           @NotNull
           @Length(max=100)
           @Column(name="'name'")
           public String getName()
           {
                return name;
           }
           public void setName(String name)
           {
                this.name = name;
           }
           
           
           @Override
           public String toString()
           {
                /*
                return "Country01(" + 
                          id + "," +
                          firstName + "," +
                          lastName +
                          ")";
                */
                return "Country01(" +
                          name +
                          ")";
           }
           
      }
      
      




      Country01List.java


      
      package com.mysite.session;
      
      import javax.ejb.Local;
      
      import com.mysite.entity.Country01;
      
      @Local
      public interface Country01List
      {
         public void getCountry01s();
         
         public Country01 getCountry01();
         
         public void destroy();
      }
      
      




      Country01ListAction.java


      
      package com.mysite.session;
      
      import static javax.ejb.TransactionAttributeType.REQUIRES_NEW;
      import static org.jboss.seam.ScopeType.SESSION;
      
      import java.io.Serializable;
      import java.util.List;
      
      import javax.ejb.Remove;
      import javax.ejb.Stateful;
      import javax.ejb.TransactionAttribute;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      
      import org.jboss.seam.annotations.Destroy;
      import org.jboss.seam.annotations.Factory;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Observer;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.datamodel.DataModel;
      import org.jboss.seam.annotations.datamodel.DataModelSelection;
      import org.jboss.seam.annotations.security.Restrict;
      import org.jboss.seam.faces.FacesMessages;
      import org.jboss.seam.log.Log;
      
      import com.mysite.entity.Country01;
      
      @Stateful
      @Scope(SESSION)
      @Name("country01List")
      @TransactionAttribute(REQUIRES_NEW)
      public class Country01ListAction implements Country01List, Serializable
      {
         private static final long serialVersionUID = 1L;
         
         @PersistenceContext
         private EntityManager em;
         
         @DataModel
         private List<Country01> country01s;
         @DataModelSelection 
         private Country01 country01;
         
         @Logger 
         private Log log;
         
         @Factory
         @Observer("country01Confirmed")
         public void getCountry01s()
         {
            country01s = em.createQuery("select c from Country01 c")
                      .getResultList();
         }
         
         
         public Country01 getCountry01()
         {
            return country01;
         }
         
         
         @Destroy
         @Remove
         public void destroy() {}
      }
      
      



      Any help you could provide on this would be so much appreciated.


      Jeff

        • 1. Re: Using new matchingEntityConverter class. Getting java.lang.ClassCastException
          christian.bauer

          1. I don't remember that limitation and I have successfully tested my converter with h:selectManyCheckbox.


          2. You can name the @Id property whatever you want, convention is however id as that is also the implied and reserved named in older versions of the Hibernate Query Language. It makes things easier.


          3. I've added the imports to the example here. But you are getting a ClassCastException, so obviously something with your deployment/configuration is wrong. It might have something to do with wrong imports but I doubt it.

          • 2. Re: Using new matchingEntityConverter class. Getting java.lang.ClassCastException
            bsgcic

            Christian,


            Thank you for your input and review.


            I will change the names of my ids to id to keep with standards.


            I just confirmed that I am using the same imports for the matchingEntityConverter class that you updated on the Documentation/DropdownBoxesWithEntitiesAndPageScope page.


            I will re-check the deployment/configurations and will post again. I wonder if my using Postgresql for jboss itself and the app would have anything to do with the issues. I was guessing not but I don't know. I used the booking example as my starting point and have been adding to and modifying that.


            Thanks again,
            Jeff

            • 3. Re: Using new matchingEntityConverter class. Getting java.lang.ClassCastException
              bsgcic

              I forgot to mention, Eclipse is indicating the following warnings in the matchingEntityConverter class:



              The serializable class MatchingEntityConverter does not declare a static final serialVersionUID field of type long

              public class MatchingEntityConverter implements javax.faces.convert.Converter, Serializable {
              






              AbstractEntityLoader is a raw type. References to generic type AbstractEntityLoader<T> should be parameterized

              private AbstractEntityLoader entityLoader;
              





              Set is a raw type. References to generic type Set<E> should be parameterized



              HashSet is a raw type. References to generic type HashSet<E> should be parameterized

              Set items = new HashSet();
              






              Collection is a raw type. References to generic type Collection<E> should be parameterized

              for (Object selectItemsValue : (Collection) selectItems.getValue()) {
              






              Type safety: The method add(Object) belongs to the raw type Set. References to generic type Set<E> should be parameterized

              items.add(selectItem.getValue());
              



              • 4. Re: Using new matchingEntityConverter class. Getting java.lang.ClassCastException
                kragoth

                Jeff Wexler wrote on Sep 16, 2009 06:01:


                I forgot to mention, Eclipse is indicating the following warnings in the matchingEntityConverter class:


                The serializable class MatchingEntityConverter does not declare a static final serialVersionUID field of type long

                public class MatchingEntityConverter implements javax.faces.convert.Converter, Serializable {
                






                AbstractEntityLoader is a raw type. References to generic type AbstractEntityLoader<T> should be parameterized

                private AbstractEntityLoader entityLoader;
                





                Set is a raw type. References to generic type Set<E> should be parameterized



                HashSet is a raw type. References to generic type HashSet<E> should be parameterized

                Set items = new HashSet();
                






                Collection is a raw type. References to generic type Collection<E> should be parameterized

                for (Object selectItemsValue : (Collection) selectItems.getValue()) {
                






                Type safety: The method add(Object) belongs to the raw type Set. References to generic type Set<E> should be parameterized

                items.add(selectItem.getValue());
                






                All of the above warnings can be safely ignored. They should however be fixed if this code is going to be going out to the community. It would be nicer then :P

                • 5. Re: Using new matchingEntityConverter class. Getting java.lang.ClassCastException
                  kragoth

                  I can't quite understand why you are getting the class cast exception.


                  java.lang.ClassCastException: org.jboss.seam.ui.JpaEntityLoader_$$_javassist_seam_8 cannot be cast to org.jboss.seam.ui.AbstractEntityLoader
                  



                  If we look at the JpaEntityLoader class


                  public class JpaEntityLoader extends AbstractEntityLoader<EntityManager>
                  



                  Looks pretty obvious that casting JpaEntityLoader to AbstractEntityLoader should work fine.


                  Can you check you havn't accidently got two different versions of the Seam library on your path?

                  • 6. Re: Using new matchingEntityConverter class. Getting java.lang.ClassCastException
                    bsgcic

                    That is a challenging question for me to answer. The following is my first attempt at answering whether there are two different version of the Seam library on the path.


                    Actually, I am not really sure where the path is defined.


                    After investigating, it appears to be ok, but I'm not completely sure. Below are the details of investigating:



                    Microsoft system environmental variables: No seam library path information defined there.


                    I use the Seam perspective of Eclipse with the Jboss Tools for Seam and initially generated the project via New Seam Web Project. At that time, Seam was version 2.1.1. I then copied in the relevant contents of the booking example files. At one point, I replaced the Seam 2.1.1 library files with the Seam 2.1.2 versions to upgrade from Seam 2.1.1 to Seam 2.1.2.


                    There are therefore 4 separate project directories in Eclipse: mysite, mysite-ear, mysite-ejb, and mysite-test.



                    The following are the libraries as viewed in the exploded directories of the default jboss server:



                    ear root directory:
                    (Below each are version info from the MANIFEST.MF in the respective jar files)


                    antlr-runtime.jar
                      Created-By: 1.5.0_07 (Apple Computer, Inc.)
                    commons-beanutils.jar
                      Ant-Version: Apache Ant 1.5.3 
                      Created-By: 1.4.1_01-b01 (Sun Microsystems Inc.)
                      Specification-Version: 1.6
                    commons-digester.jar
                      Ant-Version: Apache Ant 1.5.3 
                      Build-Jdk: 1.3.1_19
                      Implementation-Version: 1.8
                      X-Compile-Source-JDK: 1.2
                      X-Compile-Target-JDK: 1.2
                    drools-compiler.jar
                      Build-Jdk: 1.5.0_13
                      Specification-Version: 4.0.4
                      Implementation-Version: 4.0.4
                    drools-core.jar
                      (Identical to that of drools-compiler.jar above)
                    jboss-el.jar
                      Ant-Version: Apache Ant 1.7.0
                      Created-By: 1.5.0_16-133 (Apple Inc.)
                      JBoss-EL-Version: 1.0_02.CR2
                      Implementation-Version: 1.0_02.CR2
                      Specification-Version: 1.0
                    jboss-seam.jar
                      Ant-Version: Apache Ant 1.7.0
                      Created-By: 1.5.0_16-133 (Apple Inc.)
                      Seam-Version: 2.1.2
                      Implementation-Version: 2.1.2
                      Specification-Version: 2.1.2
                    jboss-seam-ui.jar
                      Build-Jdk: 1.5.0_16
                      Specification-Version: 2.1.2
                      Implementation-Version: 2.1.2
                    jbpm-jpdl.jar
                      Ant-Version: Apache Ant 1.6.5
                      Created-By: 1.5.0_11-b03 (Sun Microsystems Inc.)
                      Implementation-Version: 3.2.2 (date:12-Sep-2007 13:59)
                    mvel14.jar
                      Ant-Version: Apache Ant 1.7.0
                      Created-By: 1.6.0_01-41-release (Apple Inc.)
                      Specification-Version: 1.2.21
                      Implementation-Version: 1.2.21 January 14 2008
                    richfaces-api.jar
                      Build-Jdk: 1.5.0_12
                      Specification-Version: 3.3.0.GA
                      Implementation-Version: 3.3.0.GA
                    



                    The following are the contents of the MANIFEST.MF file within the jar META-INF directory:


                    Manifest-Version: 1.0
                    Class-Path:  
                     antlr-runtime.jar 
                     commons-beanutils.jar 
                     commons-digester.jar 
                     drools-compiler.jar  
                     drools-core.jar 
                     jboss-el.jar 
                     jboss-seam-ui.jar 
                     jbpm-jpdl.jar 
                     mvel14.jar 
                     richfaces-api.jar  
                    



                    The following are the contents of the MANIFEST.MF file within the war WEB-INF lib directory:


                    Manifest-Version: 1.0
                    Class-Path: com-oneaction-ejb.jar 
                     antlr-runtime.jar 
                     drools-compiler.jar 
                     drools-core.jar 
                     jboss-el.jar 
                     jboss-seam.jar 
                     jboss-seam-ui.jar 
                     jbpm-jpdl.jar 
                     mvel14.jar 
                     richfaces-api.jar 
                    



                    The following are the libraries in the war WEB-INF lib directory and their versions in each's respective MANIFEST.MF file:


                    commons-beanutils
                      (Same version as that of ear root directory above)
                    commons-digester
                      (Same version as that of ear root directory above)
                    jboss-seam-debug
                      Ant-Version: Apache Ant 1.7.0
                      Created-By: 1.5.0_16-133 (Apple Inc.)
                      Seam-Version: 2.1.2
                      Implementation-Version: 2.1.2
                      Specification-Version: 2.1.2
                    jboss-seam-excel
                      (Identical info as jboss-seam-debug above)
                    jboss-seam-ioc
                      (Identical info as jboss-seam-debug above)
                    jboss-seam-mail
                      (Identical info as jboss-seam-debug above)
                    jboss-seam-pdf
                      (Identical info as jboss-seam-debug above)
                    jboss-seam-remoting
                      (Identical info as jboss-seam-debug above)
                    jboss-seam-ui
                      (Same version as that of ear root directory above)
                    jsf-facelets
                      Ant-Version: Apache Ant 1.7.0
                      Created-By: 1.5.0_14-b03 (Sun Microsystems Inc.)
                      Implementation-Version: 1.1.15.B1
                    jxl
                      (No Info in the MANIFEST.MF file. Classes saved on August 9 2008 8:35 pm)
                    richfaces-impl
                      Build-Jdk: 1.5.0_12
                      Specification-Version: 3.3.0.GA
                      Implementation-Version: 3.3.0.GA
                    richfaces-ui
                      (Identical to that of richfaces-impl above)
                    



                    The following are the contents of the .classpath file within the mysite-ejb directory in Eclipse:


                    <?xml version="1.0" encoding="UTF-8"?>
                    <classpath>
                         <classpathentry kind="src" path="ejbModule"/>
                         <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
                         <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
                         <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.jboss.ide.eclipse.as.core.server.runtime.runtimeTarget/JBoss 5.1.0.GA Default Runtime"/>
                         <classpathentry kind="lib" path="/mysite-ear/EarContent/jboss-seam.jar"/>
                         <classpathentry kind="output" path="build/classes"/>
                    </classpath>
                    
                    



                    Would it be helpful for me to post contents of some of the other configuration files?

                    • 7. Re: Using new matchingEntityConverter class. Getting java.lang.ClassCastException
                      bsgcic

                      The following are the contents of the MANIFEST.MF file within the war WEB-INF lib directory:


                      Manifest-Version: 1.0
                      Class-Path: mysite-ejb.jar 
                       antlr-runtime.jar 
                       drools-compiler.jar 
                       drools-core.jar 
                       jboss-el.jar 
                       jboss-seam.jar 
                       jboss-seam-ui.jar 
                       jbpm-jpdl.jar 
                       mvel14.jar 
                       richfaces-api.jar 
                      


                      • 8. Re: Using new matchingEntityConverter class. Getting java.lang.ClassCastException
                        bsgcic

                        I made the following changes:


                        1. Renamed all @id attributes of entities to be "id" and modified all classes and xhtml files to use "id".


                        2. Changed the name of the entityManger in all places from em to entityManager


                        3. Modified components.xml to be the following:


                        <?xml version="1.0" encoding="UTF-8"?>
                        <components xmlns="http://jboss.com/products/seam/components"
                                    xmlns:bpm="http://jboss.com/products/seam/bpm"
                                    xmlns:core="http://jboss.com/products/seam/core"
                                    xmlns:drools="http://jboss.com/products/seam/drools"
                                    xmlns:framework="http://jboss.com/products/seam/framework"
                                    xmlns:mail="http://jboss.com/products/seam/mail"
                                    xmlns:persistence="http://jboss.com/products/seam/persistence"
                                    xmlns:security="http://jboss.com/products/seam/security"
                                    xmlns:transaction="http://jboss.com/products/seam/transaction"
                                    xmlns:web="http://jboss.com/products/seam/web"
                                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                    xsi:schemaLocation=
                                        "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
                                         http://jboss.com/products/seam/framework http://jboss.com/products/seam/framework-2.1.xsd
                                         http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd
                                         http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd
                                         http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
                                         http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsd
                                         http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                                         http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
                                         http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.1.xsd
                                         http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">
                        
                            <core:init jndi-pattern="@jndiPattern@" debug="true" distributable="false"/>
                        
                            <core:manager 
                                      conversation-timeout="120000"
                                            concurrent-request-timeout="500"
                                            conversation-id-parameter="cid"
                                  />
                        
                            <transaction:ejb-transaction/>
                                  
                            <persistence:entity-manager-factory name="mysiteEntityManagerFactory"
                              persistence-unit-name="mysite" installed="@loadPersistenceUnits@"/>
                              
                                  <persistence:managed-persistence-context name="entityManager" 
                                            auto-create="true"
                                            entity-manager-factory="#{mysiteEntityManagerFactory}"
                                   persistence-unit-jndi-name="java:/mysiteEntityManagerFactory"/>
                                  
                                  <component name="identifierMatchingEntityConverter"
                                            class="mysite.conversation.MatchingEntityConverter"
                                  >
                                       <property name="match">id</property>
                                  </component>
                                  
                                  
                            <security:identity authenticate-method="#{authenticator.authenticate}"/>
                        
                        </components>
                        
                        



                        Now I am getting the following errors:


                        javax.faces.FacesException: javax.el.ELException: /person04tst05.xhtml @94,83 value="#{person04Create.verify}": Error reading 'verify' on type org.javassist.tmp.java.lang.Object_$$_javassist_seam_3
                             at javax.faces.component.UIOutput.getValue(UIOutput.java:187)
                        
                        Caused by: javax.el.ELException: /person04tst05.xhtml @94,83 value="#{person04Create.verify}": Error reading 'verify' on type org.javassist.tmp.java.lang.Object_$$_javassist_seam_3
                             at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:76)
                        
                        Caused by: javax.ejb.EJBTransactionRolledbackException: java.lang.Long cannot be cast to javax.persistence.EntityManagerFactory
                             at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:115)
                        
                        



                        Stack Trace:


                        javax.faces.FacesException: javax.el.ELException: /person04tst05.xhtml @94,83 value="#{person04Create.verify}": Error reading 'verify' on type org.javassist.tmp.java.lang.Object_$$_javassist_seam_3
                             at javax.faces.component.UIOutput.getValue(UIOutput.java:187)
                             at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:201)
                             at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:284)
                             at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:154)
                             at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861)
                             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:837)
                             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:152)
                             at org.jboss.seam.ui.util.cdk.RendererBase.encodeChildren(RendererBase.java:92)
                             at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
                             at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
                             at javax.faces.render.Renderer.encodeChildren(Renderer.java:148)
                             at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
                             at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
                             at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
                             at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
                             at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
                             at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
                             at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
                             at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
                             at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
                             at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
                             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.IdentityFilter.doFilter(IdentityFilter.java:40)
                             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                             at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                             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:178)
                             at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                             at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
                             at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
                             at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
                             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                             at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
                             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                             at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
                             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:235)
                             at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                             at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
                             at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
                             at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
                             at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
                             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:158)
                             at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                             at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
                             at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
                             at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
                             at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
                             at java.lang.Thread.run(Thread.java:619)
                        Caused by: javax.el.ELException: /person04tst05.xhtml @94,83 value="#{person04Create.verify}": Error reading 'verify' on type org.javassist.tmp.java.lang.Object_$$_javassist_seam_3
                             at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:76)
                             at javax.faces.component.UIOutput.getValue(UIOutput.java:184)
                             ... 68 more
                        Caused by: javax.ejb.EJBTransactionRolledbackException: java.lang.Long cannot be cast to javax.persistence.EntityManagerFactory
                             at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:115)
                             at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
                             at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:194)
                             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                             at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
                             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                             at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
                             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                             at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:201)
                             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                             at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:186)
                             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                             at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)
                             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                             at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)
                             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                             at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
                             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                             at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:176)
                             at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:216)
                             at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:207)
                             at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:164)
                             at $Proxy620.getVerify(Unknown Source)
                             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:22)
                             at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
                             at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
                             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                             at org.jboss.seam.ejb.RemoveInterceptor.aroundInvoke(RemoveInterceptor.java:43)
                             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.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
                             at org.javassist.tmp.java.lang.Object_$$_javassist_seam_3.getVerify(Object_$$_javassist_seam_3.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 javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
                             at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
                             at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
                             at org.jboss.el.parser.AstPropertySuffix.getValue(AstPropertySuffix.java:53)
                             at org.jboss.el.parser.AstValue.getValue(AstValue.java:67)
                             at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
                             at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
                             ... 69 more
                        Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to javax.persistence.EntityManagerFactory
                             at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:234)
                             at org.jboss.seam.persistence.ManagedPersistenceContext.initEntityManager(ManagedPersistenceContext.java:78)
                             at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:107)
                             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:22)
                             at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
                             at org.jboss.seam.Component.callComponentMethod(Component.java:2249)
                             at org.jboss.seam.Component.unwrap(Component.java:2275)
                             at org.jboss.seam.Component.getInstance(Component.java:2041)
                             at org.jboss.seam.Component.getInstance(Component.java:1983)
                             at org.jboss.seam.Component.getInstance(Component.java:1977)
                             at org.jboss.seam.Component.getInstanceInAllNamespaces(Component.java:2349)
                             at org.jboss.seam.Component.getValueToInject(Component.java:2301)
                             at org.jboss.seam.Component.injectAttributes(Component.java:1736)
                             at org.jboss.seam.Component.inject(Component.java:1554)
                             at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
                             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                             at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
                             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                             at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29)
                             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                             at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:30)
                             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.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
                             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.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:83)
                             at org.jboss.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:70)
                             at org.jboss.ejb3.EJBContainerInvocationWrapper.invokeNext(EJBContainerInvocationWrapper.java:59)
                             at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:73)
                             at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:59)
                             at sun.reflect.GeneratedMethodAccessor470.invoke(Unknown Source)
                             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                             at java.lang.reflect.Method.invoke(Method.java:597)
                             at org.jboss.aop.advice.PerJoinpointAdvice.invoke(PerJoinpointAdvice.java:174)
                             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                             at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.fillMethod(InvocationContextInterceptor.java:72)
                             at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_fillMethod_21290107.invoke(InvocationContextInterceptor_z_fillMethod_21290107.java)
                             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                             at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:88)
                             at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_21290107.invoke(InvocationContextInterceptor_z_setup_21290107.java)
                             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                             at org.jboss.ejb3.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:62)
                             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                             at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:60)
                             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                             at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:56)
                             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                             at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
                             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                             at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
                             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                             at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:81)
                             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                             at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
                             ... 114 more
                        
                        



                        persistence.xml is the following:


                        <?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="mysite" transaction-type="JTA">
                              <provider>org.hibernate.ejb.HibernatePersistence</provider>
                              <jta-data-source>java:/mysiteDatasource</jta-data-source>
                              <properties>
                                 <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
                                 <property name="hibernate.show_sql" value="true"/>
                                 <property name="hibernate.format_sql" value="true"/>
                                 <property name="jboss.entity.manager.factory.jndi.name" value="java:/mysiteEntityManagerFactory"/>
                                 <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
                                 <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
                              </properties>
                           </persistence-unit>
                            
                        </persistence>
                        
                        



                        Any ideas as to the cause of the issue?


                        Thanks


                        Jeff

                        • 9. Re: Using new matchingEntityConverter class. Getting java.lang.ClassCastException
                          dendroid66

                          Hello Jeff,
                          I'm also trying to implement custom converter and I have exactly the same problem as you - ClassCastException.
                          Are you sure that after having the changes you resolved THIS exception and you are not falling in javax.el.ELException BEFORE the ClassCast should happen? I'm asking you because classcast exception concerns wrong jar files (mixing libraries).


                          Thank you in advance.

                          • 10. Re: Using new matchingEntityConverter class. Getting java.lang.ClassCastException
                            bsgcic

                            Hello Alexander,


                            I found some issues with jar files since September which I believe I corrected. However, I have not attempted to implement the custom converter since September and ended up getting the s:convertEntity to work (which was extremely challenging for me to fix the issues at the time).


                            I do not know as of yet whether the changes of jar files would have corrected the issue with the custom converter. I plan to take another look at it again tomorrow and see if I can post some further insight into it.


                            Regards,


                            Jeff

                            • 11. Re: Using new matchingEntityConverter class. Getting java.lang.ClassCastException
                              dendroid66

                              Hello Jeff,



                              Thank you for the answer.
                              In fact, I wish to get this s:convertEntity working by all means.
                              Of course, I have already tried to use this built-in converter but failed.
                              Please, tell me, did you changed somehow equals() and hashCode()?
                              My methods are not working well :(


                                @Override
                                public int hashCode() {
                                  final int prime = 31;
                                  int result = 1;
                                  result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
                                  return result;
                                }

                                @Override
                                public boolean equals(Object obj) {
                                  if (this == obj) {
                                    return true;
                                  }
                                  if (obj == null) {
                                    return false;
                                  }
                                  //http://www.seamframework.org/Documentation/IGetValueIsNotAValidOptionWhenUsingSselectItemsAndSconvertEntityOrACustomConverter
                                  //    if (getClass() != obj.getClass()) {
                                  //      return false;
                                  //    }
                                  Projects other = (Projects) obj;
                                  if (getId() == null) {
                                    if (other.getId() != null) {
                                      return false;
                                    }
                                  } else if (!getId().equals(other.getId())) {
                                    return false;
                                  }
                                  return true;
                                }


                              I took a glance at
                              https://www.hibernate.org/109.html
                              as well as
                              http://djeang.blogspot.com/2005/08/override-equals-and-hashcode-methods.html


                              Thanks.

                              • 12. Re: Using new matchingEntityConverter class. Getting java.lang.ClassCastException
                                dendroid66

                                Oh, here is a good formatting:




                                  @Override
                                  public int hashCode() {
                                    final int prime = 31;
                                    int result = 1;
                                    result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
                                    return result;
                                  }
                                
                                  @Override
                                  public boolean equals(Object obj) {
                                    if (this == obj) {
                                      return true;
                                    }
                                    if (obj == null) {
                                      return false;
                                    }
                                    //http://www.seamframework.org/Documentation/IGetValueIsNotAValidOptionWhenUsingSselectItemsAndSconvertEntityOrACustomConverter
                                //    if (getClass() != obj.getClass()) {
                                //      return false;
                                //    }
                                    Projects other = (Projects) obj;
                                    if (getId() == null) {
                                      if (other.getId() != null) {
                                        return false;
                                      }
                                    } else if (!getId().equals(other.getId())) {
                                      return false;
                                    }
                                    return true;
                                  }



                                • 13. Re: Using new matchingEntityConverter class. Getting java.lang.ClassCastException
                                  bsgcic

                                  Hello Alexander,


                                  I just recalled changes that enabled the s:convertEntity to work for me. I took a different approach than via modification to hashcode() and equals(Object obj).


                                  My initial solution was by making <framework:entity-query entries in components.xml.


                                  Later, after I cleaned up my libraries issues, I got a solution more preferable to me working which I will describe below. I assume that you have read the following post because you were able to find Christian Bauer's MatchingEntityConverter.


                                  Dropdowns in JSF: Validating the selected value


                                  Near the top of that post, there is a section titled "The Workarounds". In your solution, it appears that you are attempting the workaround #2. The one that I got to work was workaround #1 "1.Display the list and submit the form inside the same long running conversation (so that the persistence context returns the same object both times)."


                                  So, this is what I did. If I recall correctly, the @Scope(CONVERSATION) on the class, the @PersistenceContext(type=PersistenceContextType.EXTENDED) and
                                  @In(create=true) on the entityManager and the @Factory on getMyOptionsList() were important. The @TransactionAttribute(REQUIRES_NEW) might also have been important.


                                  package com.mysite;
                                  
                                  import static org.jboss.seam.ScopeType.CONVERSATION;
                                  import static javax.ejb.TransactionAttributeType.REQUIRES_NEW;
                                  import java.io.Serializable;
                                  import java.util.List;
                                  import javax.ejb.Remove;
                                  import javax.ejb.Stateful;
                                  import javax.ejb.TransactionAttribute;
                                  import javax.persistence.EntityManager;
                                  import javax.persistence.PersistenceContext;
                                  import javax.persistence.PersistenceContextType;
                                  
                                  import org.jboss.seam.annotations.Create;
                                  import org.jboss.seam.annotations.Destroy;
                                  import org.jboss.seam.annotations.Factory;
                                  import org.jboss.seam.annotations.In;
                                  import org.jboss.seam.annotations.Name;
                                  import org.jboss.seam.annotations.Scope;
                                  
                                  @Stateful
                                  @Scope(CONVERSATION)
                                  @Name("myOptionList")
                                  @TransactionAttribute(REQUIRES_NEW)
                                  public class MyOptionListAction implements MyOptionList, Serializable
                                  {
                                  private static final long serialVersionUID = 4292649042195284573L;
                                  public MyOptionListAction() {};
                                  @PersistenceContext(type=PersistenceContextType.EXTENDED)
                                  @In(create=true)
                                  private EntityManager entityManager;
                                  
                                  private List<MyOption> myOptionsList;
                                  
                                  @Create
                                  public void create() { getMyOptionsList(); }
                                  
                                  @SuppressWarnings("unchecked")
                                  @Factory
                                  public List<MyOption> getMyOptionsList()
                                  {
                                   return (List<MyOption>) entityManager.createQuery(
                                    "select r from MyOption r where " + 
                                    "r.someParameter.id = :someParameterId " + 
                                    "order by r.order asc")
                                                    
                                    .setParameter("someParameterId", valueIWantToMatchTo)
                                    .getResultList();
                                  }      
                                  
                                  public void setMyOptionsList(List<MyOption> myOptionsList)
                                  { this.myOptionsList = myOptionsList; }
                                  
                                  @Destroy
                                  @Remove
                                  public void destroy() {}
                                  }
                                  
                                  



                                  And then in the conversation object where I capture the value of the s:convertEntity and use it, I ensure that I inject the SAME persistence context. This was key.


                                  
                                  @Stateful
                                  @Name("useOfMyOptionsList")
                                  @Scope(ScopeType.CONVERSATION)
                                  @TransactionAttribute(REQUIRES_NEW)
                                  public class UseOfMyOptionsListAction implements UseOfMyOptionsList
                                  {
                                  
                                  public UseOfMyOptionsListAction() {}
                                  
                                  @PersistenceContext(type=PersistenceContextType.EXTENDED)
                                  @In(create=true)
                                  private EntityManager entityManager;
                                  
                                  @DataModel
                                  private List<MyOption> chosenMyOptions = null;
                                  
                                  The, the rest of the code.
                                  
                                  }
                                  
                                  



                                  Here is the xhtml code:


                                  <h:selectManyListbox id="theSelectManyCheckboxlistId"
                                   value="#{useOfMyOptionsList.chosenMyOptions}"
                                   valueChangeListener="#{useOfMyOptionsList.vclForchosenMyOptions}"
                                  >
                                  
                                  <s:selectItems value="#{myOptionsList}"
                                   var="chosenMyOptionVar"
                                   label="#{chosenMyOptionVar.label}"
                                  />
                                  <s:convertEntity />
                                  
                                  


                                  • 14. Re: Using new matchingEntityConverter class. Getting java.lang.ClassCastException
                                    dendroid66

                                    Good news Jeff!


                                    Yesterday I found that @Scope(CONVERSATION) really does the job.
                                    I mean that I have already used the converter but it did not help to make the restriction in my EJBQL statement.
                                    In fact I use only EntityHome / EntityQuery internal framework to have rapid development. Certainly, I experienced many problems (probably I should use the latest SEAM) but it's worth it.


                                    I see that you use h:selectManyListbox. It is my next step and I've got a problem from converter (Caused by org.jboss.seam.Entity$NotEntityException with message: Not an entity class: java.util.ArrayList).


                                    Are you sure that the @Factory is a must for the public


                                    List<MyOption> getMyOptionsList()



                                    ?


                                    Why you separated the list for options to the UseOfMyOptionsListAction instead of inplace definition of vclForchosenMyOptions? Is it obligatory?


                                    Thank you.

                                    1 2 Previous Next