4 Replies Latest reply on Dec 28, 2009 9:04 PM by caiogallo

    Problens with s:convertEntity

    caiogallo

      Hello,


      I'm trying to use the s:convertEntity but its cause this exception:


      org.hibernate.ejb.EntityManagerFactoryImpl cannot be cast to javax.persistence.EntityManager


      My project is using Seam 2.2, weblogic 10.3 with Eclipse.


      I managed to go through several configuration problem with the help of google and also the reference guide of Seam but that I found few things listed, it's almost making me give up the seam and return to the ADF.


      Does anyone have any idea what this problem?


      Thank you very much

        • 1. Re: Problens with s:convertEntity
          caiogallo

          Hi.


          I added this line in my components.xml and the error message has changed to



          java.lang.NullPointerException
                  at org.jboss.seam.framework.HibernateEntityIdentifier.<init>(HibernateEntityIdentifier.java:13)
                  at org.jboss.seam.ui.HibernateEntityLoader.createIdentifier(HibernateEntityLoader.java:28)
                  at org.jboss.seam.ui.AbstractEntityLoader.put(AbstractEntityLoader.java:46)
                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


          Any Idea?


          Thanks

          • 2. Re: Problens with s:convertEntity
            mikkus70

            Please post the code where you're experiencing the error (the form field you're populating with your entity converter, the entity you're converting, the line in components.xml you changed and eventually other related info)...


            Anyway, <s:convertEntity/> does its work but has several drawbacks you need to be aware of when using it. First, it takes the entity or entities you're converting, stores them in a conversation-scoped map and returns the index of each entity in the map so that it can retrieve them back from that same map when submitting. So, <s:convertEntity/> must be used in a conversation so that the entity cache survives postbacks and navigation.


            For this reason, I frequently find entity conversion to be overshoot and just pass the entity primary key (if using surrogate keys) and use that as needed.


            The exception you're experiencing means your HibernatePersistenceProvider or Session do not exist. Apparently, your persistence configuration has some issues.

            • 3. Re: Problens with s:convertEntity
              caiogallo
              Hello Emir, thanks for response.

              My form's code is;


              |...
              <rich:comboBox value="#{escopo.ataEscopo}"
                   defaultLabel="#{msg['combo.selecionar']}">
                   <s:selectItems var="escopo"
                        value="#{escopoAction.listaTodosExcetoSelecionado}"
                        label="#{escopo.desEscopo}" itemValue="#{escopo}" />
                   <s:convertEntity />
              </rich:comboBox>`
              ...|

              The components.xml:


              |<core:init jndi-pattern="@jndiPattern@" />

              <core:manager concurrent-request-timeout="500"
                   conversation-timeout="120000" conversation-id-parameter="cid"
                   parent-conversation-id-parameter="pid" />

              <web:hot-deploy-filter url-pattern="*.seam" />

              <persistence:entity-manager-factory name="entityManager" auto-create="true" persistence-unit-name="SgiAtaEletronica" />|

              My Entity:



              '@Entity
              @Table(name="ATA_ESCOPO")
              public class AtaEscopo implements Serializable {
                   private static final long serialVersionUID = 1L;

                   @Id
                   @SequenceGenerator(name="ATA_ESCOPO_IDATAESCOPO_GENERATOR", sequenceName="SEQ_ATA_ESCOPO", allocationSize=1)
                   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="ATA_ESCOPO_IDATAESCOPO_GENERATOR")
                   @Column(name="ID_ATA_ESCOPO")
                   private Long idAtaEscopo;

                   @Column(name="DES_ESCOPO")
                   private String desEscopo;

                   @Column(name="DES_SQL")
                   private String desSql;

                   @Column(name="ID_ENT_USUARIO")
                   private Long idEntUsuario;

                   //bi-directional many-to-one association to AtaAssuntoXEscopo
                   @OneToMany(mappedBy="ataEscopo")
                   private List<AtaAssuntoXEscopo> ataAssuntoXEscopos;

                   //bi-directional many-to-one association to AtaEscopo
                  @ManyToOne
                   @JoinColumn(name="ID_ATA_ESCOPO_PAI", nullable = true)
                   private AtaEscopo ataEscopo;

                   @Override
                   public boolean equals(Object obj) {
                        if(obj != null) {
                             if(obj instanceof AtaEscopo) {
                                  AtaEscopo tmp = (AtaEscopo) obj;
                                  if(idAtaEscopo != null && tmp.getIdAtaEscopo() != null && idAtaEscopo.equals(tmp.getIdAtaEscopo())) {
                                       return true;
                                  }
                             }
                        }
                        return super.equals(obj);
                   }

                   @Override
                   public int hashCode() {
                        try {
                             return idAtaEscopo.intValue();
                        }
                        catch(Exception e) {
                             System.out.println("Erro obtendo hashcode " + e.getMessage());
                             return super.hashCode();
                        }
                        
                   }

                   //bi-directional many-to-one association to AtaEscopo
                   @OneToMany(mappedBy="ataEscopo")
                   private List<AtaEscopo> ataEscopos;

                  public AtaEscopo() {
                  }

                   public Long getIdAtaEscopo() {
                        return this.idAtaEscopo;
                   }

                   public void setIdAtaEscopo(Long idAtaEscopo) {
                        this.idAtaEscopo = idAtaEscopo;
                   }

                   public String getDesEscopo() {
                        return this.desEscopo;
                   }

                   public void setDesEscopo(String desEscopo) {
                        this.desEscopo = desEscopo;
                   }

                   public Long getIdEntUsuario() {
                        return this.idEntUsuario;
                   }

                   public void setIdEntUsuario(Long idEntUsuario) {
                        this.idEntUsuario = idEntUsuario;
                   }

                   public List<AtaAssuntoXEscopo> getAtaAssuntoXEscopos() {
                        return this.ataAssuntoXEscopos;
                   }

                   public void setAtaAssuntoXEscopos(List<AtaAssuntoXEscopo> ataAssuntoXEscopos) {
                        this.ataAssuntoXEscopos = ataAssuntoXEscopos;
                   }
                   
                   public AtaEscopo getAtaEscopo() {
                        return this.ataEscopo;
                   }

                   public void setAtaEscopo(AtaEscopo ataEscopo) {
                        this.ataEscopo = ataEscopo;
                   }
                   
                   public List<AtaEscopo> getAtaEscopos() {
                        return this.ataEscopos;
                   }

                   public void setAtaEscopos(List<AtaEscopo> ataEscopos) {
                        this.ataEscopos = ataEscopos;
                   }

                   public void setDesSql(String desSql) {
                        this.desSql = desSql;
                   }

                   public String getDesSql() {
                        return desSql;
                   }
                   
                   public String toString() {
                        return desEscopo;
                   }
              }`


              And the persistence.xml:

              |<persistence-unit name="SgiAtaEletronica">
                   <provider>org.hibernate.ejb.HibernatePersistence</provider>
                   <jta-data-source>ICECDS</jta-data-source>

                   <class>icec.sgi.ata.persistence.pojos.AtaEscopo</class>

                   <properties>
                        <property name="hibernate.show_sql" value="true" />          
                        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect" />
                        <property name="hibernate.query.factory_class"
                             value="org.hibernate.hql.ast.ASTQueryTranslatorFactory" />
                        <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" />
                        <property name="hibernate.transaction.manager_lookup_class"
                             value="org.hibernate.transaction.WeblogicTransactionManagerLookup" />
                   </properties>
              </persistence-unit>|

              Thanks.
              • 4. Re: Problens with s:convertEntity
                caiogallo

                Hi Emir


                I encontred the solution of my problem. I'm not using Seam managed transaction, I was using EJB to manage my transactions.


                After change to Seam, the convertEntity works fine.


                Thanks for help.