3 Replies Latest reply on Feb 1, 2010 3:49 AM by Rushit Desai

    Erro org.hibernate.TransientObjectException: The instance was not associated with this session

    IVAN BATISTA MORENO Newbie

      what problem?


      entity classe



      @Entity
      @Table(name = "cargo")
      public class Cargo implements java.io.Serializable {
      
           private static final long serialVersionUID = 2632056225124288939L;
           private int codigoCargo;
           private String nomeCargo;
      
           public Cargo() {
           }
      
           public Cargo(int codigoCargo, String nomeCargo) {
                this.codigoCargo = codigoCargo;
                this.nomeCargo = nomeCargo;
           }
      
           @Id
           @Column(name = "codigo_cargo", unique = true, nullable = false)
           @NotNull
           public int getCodigoCargo() {
                return this.codigoCargo;
           }
      
           public void setCodigoCargo(int codigoCargo) {
                this.codigoCargo = codigoCargo;
           }
      
           @Column(name = "nome_cargo", nullable = false, length = 75)
           @NotNull
           @Length(max = 75)
           public String getNomeCargo() {
                return this.nomeCargo;
           }
      
           public void setNomeCargo(String nomeCargo) {
                this.nomeCargo = nomeCargo;
           }
      
           @Override
           public boolean equals(Object obj) {
                if (obj == null)
                     return false;
                else if (!(obj instanceof Cargo))
                     return false;
                else if (((Cargo) obj).getCodigoCargo() == this.getCodigoCargo())
                     return true;
                else
                     return false;
           }
      
           @Override
           public int hashCode() {
                int result = 17;
      
                result = 37 * result + (int) this.getCodigoCargo();
                return result;
           }
      
      }




      ManagedBean



      @Name("usuarioAction")
      @Scope(ScopeType.PAGE)
      public class UsuarioAction extends SropAbstractActionCommand {
      
           private static final long serialVersionUID = -2580358142278471330L;
      
           @In
           private Session seamDatabase;
      
           private List<Cargo> cargos = null;
      
           private Cargo cargo = new Cargo();
      
           @Override
           public void doAdicionar() {
                this.getController().setHabilitaNovoCadastro(false);
                this.getController().setCurrentState(ControllerState.ADICIONAR_STATE);
           }
      
           @Override
           public void doCancelar() {
                this.getController().setCurrentState(ControllerState.PESQUISAR_STATE);
           }
      
           @Override
           public void doEditar() {
                // TODO Auto-generated method stub
           }
      
           @Override
           public void doLimpar() {
                // TODO Auto-generated method stub
           }
      
           @Override
           public void doListar() {
                // TODO Auto-generated method stub
           }
      
           @Override
           public void doPesquisar() {
      
                FacesMessages.instance().add(Severity.INFO, "Nenhum registro foi encontrado!");
      
                this.getController().setHabilitaNovoCadastro(true);
      
           }
      
           @Override
           public void doSalvar() {
                this.getController().setCurrentState(ControllerState.PESQUISAR_STATE);
                
                if (cargo != null)
                     System.out.println(cargo.getNomeCargo());
                
      
           }
      
           @SuppressWarnings("unchecked")
           public List<Cargo> getCargos() {
      
                if (cargos == null) {
                     cargos = seamDatabase.createCriteria(Cargo.class).list();
                }
      
                return cargos;
      
           }
      
           public void setCargos(List<Cargo> cargos) {
                this.cargos = cargos;
           }
      
           public Cargo getCargo() {
                return cargo;
           }
      
           public void setCargo(Cargo cargo) {
                this.cargo = cargo;
           }
      }"
      



      components.xml



      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components" xmlns:core="http://jboss.com/products/seam/core" xmlns:persistence="http://jboss.com/products/seam/persistence"
           xmlns:security="http://jboss.com/products/seam/security" xmlns:drools="http://jboss.com/products/seam/drools" xmlns:web="http://jboss.com/products/seam/web"
           xmlns:mail="http://jboss.com/products/seam/mail" xmlns:transaction="http://jboss.com/products/seam/transaction" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:ui="http://jboss.com/products/seam/ui"
           xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
               http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd
              http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
              http://jboss.com/products/seam/ui http://jboss.com/products/seam/ui-2.1.xsd
              http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsd
              http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd
              http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd">
      
           <core:manager conversation-timeout="120000" concurrent-request-timeout="500" conversation-id-parameter="cid" />
      
           <persistence:hibernate-session-factory name="hibernateSessionFactory" />
      
           <persistence:managed-hibernate-session name="seamDatabase" session-factory="#{hibernateSessionFactory}" auto-create="true" />
      
           <transaction:hibernate-transaction session="#{seamDatabase}" />
      
           <ui:hibernate-entity-loader session="#{seamDatabase}" />
      
      </components>




      user.xhmtl



                     <h:form>
      
      
                          <h:selectOneMenu 
                               id="campoCargo"
                              label="Cargo" value="#{usuarioAction.cargo}" required="true">
                               <s:selectItems var="cargo" value="#{usuarioAction.cargos}" 
                                label="#{cargo.nomeCargo}" noSelectionLabel="-- SELECIONA UM CARGO --"/>
                             <s:convertEntity/>
                         </h:selectOneMenu>
      
                          <h:commandButton action="#{usuarioAction.doSalvar}" value="Salvar" />               
      
                             
                     </h:form>



        • 1. Re: Erro org.hibernate.TransientObjectException: The instance was not associated with this session
          IVAN BATISTA MORENO Newbie

          error in console



          17/07/2009 09:52:37 com.sun.facelets.FaceletViewHandler handleRenderException
          SEVERE: Error Rendering View[/pagina/user.xhtml]
          org.hibernate.TransientObjectException: The instance was not associated with this session
               at org.hibernate.impl.SessionImpl.getIdentifier(SessionImpl.java:1375)
               at org.jboss.seam.persistence.HibernateSessionProxy.getIdentifier(HibernateSessionProxy.java:236)
               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)
               at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
               at java.lang.reflect.Method.invoke(Unknown Source)
               at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
               at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
               at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:95)
               at org.jboss.seam.util.Work.workInTransaction(Work.java:47)
               at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:89)
               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.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
               at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
               at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
               at org.jboss.seam.ui.HibernateEntityLoader_$$_javassist_2.put(HibernateEntityLoader_$$_javassist_2.java)
               at org.jboss.seam.ui.EntityConverter.getAsString(EntityConverter.java:65)
               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:759)
               at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:819)
               at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:280)
               at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861)
               at javax.faces.component.UIComponent.encodeAll(UIComponent.java:946)
               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:936)
               at javax.faces.component.UIComponent.encodeAll(UIComponent.java:942)
               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:109)
               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:58)
               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.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
               at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
               at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
               at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
               at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
               at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
               at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
               at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
               at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
               at java.lang.Thread.run(Unknown Source)
          



          • 3. Re: Erro org.hibernate.TransientObjectException: The instance was not associated with this session
            Rushit Desai Newbie

            I am also getting the same error while calling valueChangeListener on list box.


            Has anyone found solution to this problem?