6 Replies Latest reply on Oct 6, 2009 9:09 AM by Bernard Labno

    Session value transient when injected into EntityHome class

    James Domagalski Newbie

      Hello all,


      I have a persistence issue that has been bugging me, if i could get some ideas on it, I would very much appreciat it.  


      I currently have the authenticator out-ject to the session the user who logged in, the variable labeled currentUser. I would like to use currentUser in other classes where the User needs to be saved as an owner of an object.   An example of this is the Category class.  Below are the Authenticator.java, Category.java, and CategoryHome.java



      Authenticator.java


      @Name("authenticator")
      public class Authenticator
      {
              @Logger
              private Log log;
      
              @In
              private Identity identity;
              @In
              private Credentials credentials;
              @In
              private EntityManager entityManager;
      
              @Out(scope = ScopeType.SESSION, required=false)
              private User currentUser;
                 
              public boolean authenticate() {
      
                      log.info("authenticating {0}", credentials.getUsername());
      
                      try {
                              currentUser = (User) entityManager
                              .createQuery(
                                              "select user from User user where user.username = #{credentials.username} and user.password = #{credentials.password}")
                              .getSingleResult();                     
                      } catch (NoResultException e) {
                      }
                      
                      boolean authenticated = (currentUser != null);
      
                      if (authenticated) {
                              log.info("Authenticated #{credentials.username}");
                              identity.addRole(currentUser.getAccountType().name());
                              return true;
                      } else {
                              return false;
                      }
              }
      }




      CategoryHome.java


      @Name("categoryHome")
      @Restrict("#{identity.loggedIn}")
      public class CategoryHome extends EntityHome<Category> {
      
              @In(required = false, scope = ScopeType.SESSION)
              private User currentUser;
              
              public void setCategoryId(Long id) {
                      setId(id);
              }
      
              public Long getCategoryId() {
                      return (Long) getId();
              }
      
              @Override
              protected Category createInstance() {
                      Category category = super.createInstance();
                      category.setOwner(currentUser);
                      return category;
              }
      
              public void load() {
                      if (isIdDefined()) {
                              wire();
                      }
              }
      
              public void wire() {
                      getInstance();
              }
      
              public boolean isWired() {
                      return true;
              }
      
              public Category getDefinedInstance() {
                      return isIdDefined() ? getInstance() : null;
              }
      
      }
      



      Category.java


      @Entity
      public class Category {
              private Long id;
              private User owner;
              private String name;
                      
          @Id @GeneratedValue
          public Long getId() { return id; }
          public void setId(Long id) {
              this.id = id;
          }
          
          @ManyToOne(fetch = FetchType.LAZY)
          @JoinColumn(nullable = false)
              public User getOwner() {
                      return owner;
              }
              public void setOwner(User owner) {
                      this.owner = owner;
              }
              
              public String getName() {
                      return name;
              }
              public void setName(String name) {
                      this.name = name;
              }
              
              public String toString(){
                      return name;
              }
      }
      





      The issue I am having is when I call persist in the CategoryHome.java  I always seem to get the error :


      Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: org.domain.examgenerator.entity.Category.owner
              at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
              at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
              at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
              at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
              at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
              at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
              at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
              at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
              at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
              at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
              at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:212)
              ... 87 more
      



      I know that the currentUser being injected into CategoryHome is not null. ( I have used the debugger to confirm this to be true).
      This leaves me to the conclusion that currentUser is transient.   My question is how do I resolve it so that the currentUser value found in the session stays persistent?


      I have tried merging the currentUser using entityManager within the CategoryHome class, which is shown below


       
      @Override
      protected Category createInstance() {
          Category category = super.createInstance();
          currentUser = this.getEntityManager().merge(currentUser);
          category.setOwner(currentUser);
          return category;
      }
      



      but I get the following error.


      Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'student' for key 'username'
              at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
              at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
              at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
              at java.lang.reflect.Constructor.newInstance(Unknown Source)
              at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
              at com.mysql.jdbc.Util.getInstance(Util.java:381)
              at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
              at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
              at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558)
              at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)
              at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
              at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109)
              at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)
              at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2077)
              at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2362)
              at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2280)
              at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2265)
              at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:365)
              at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
              at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
              ... 104 more
      




      I am pretty new to seam so any help would be very much appreciated.


      Thank you for you time.

        • 1. Re: Session value transient when injected into EntityHome class
          James Domagalski Newbie

          So I worked on this a bit and found that if I get a fresh copy of the User object from the Entity Manager using the find method everything works fine. 


          Working createInstance method found in CategoryHome:




               @Override
               protected Category createInstance() {
                    Category category = super.createInstance();
                    currentUser = this.getEntityManager().find(User.class,currentUser.getId());
                    category.setOwner(currentUser);
                    return category;
               }
          



          Even though this works, this would mean I would have to do this before using the currentUser in any of my other entityHome classes.  Is this a proper way of handling solving this issue, or is there a better way that I am not considering?


          Thanks

          • 2. Re: Session value transient when injected into EntityHome class
            Bernard Labno Master

            I've always considered transient entities to be ones without id set. So check once more just before persist if owner is not null. Please post full stack traces and User class.

            • 3. Re: Session value transient when injected into EntityHome class
              James Domagalski Newbie

              Thanks for your response.


              I took another look before persist at the currentUser variable and as well as the owner variable within the CatagoryHome instance. Both are not null.  This is a copy of the variables of current user before persist.


              Here is a copy of the instance variables right before persist is called.  As you can see Owner is not null and it does have a value in for id.


              instance     Category  (id=425)     
                   id     null     
                   name     "test" (id=558)     
                   owner     User  (id=418)     
                        accountType     AccountTypeEnum  (id=427)     
                        emailAddress     "temp@email.com" (id=431)     
                        firstName     "A" (id=434)     
                        id     Long  (id=435)     
                             value     1     
                        lastName     "Student" (id=437)     
                        password     "test" (id=439)     
                        username     "student" (id=440)     
                        version     null
              



              User.java


              @Entity
              @Role(name = "currentUser", scope= ScopeType.SESSION)
              public class User implements Serializable
              {
                   private Long id;
                  private Integer version;
                  private String username;
                  private String password;
                  private String firstName;
                  private String lastName;
                  private String emailAddress;
                  private AccountTypeEnum accountType;
              
                  // add additional entity attributes
                  @Length(max = 12)
                  @NotNull
                  @Column(unique=true)
                  public String getUsername() {
                      return username;
                  }
              
                  public void setUsername(String username) {
                      this.username = username;
                  }
              
                  @Length(max = 15)
                  @NotNull
                  public String getPassword() {
                        return password;
                   }
              
                   public void setPassword(String password) {
                        this.password = password;
                   }
              
                   @Length(max = 50)
                  @NotNull
                   public String getFirstName() {
                        return firstName;
                   }
              
                   public void setFirstName(String firstName) {
                        this.firstName = firstName;
                   }
              
                   @Length(max = 50)
                  @NotNull
                   public String getLastName() {
                        return lastName;
                   }
              
                   public void setLastName(String lastName) {
                        this.lastName = lastName;
                   }
              
                  @NotNull
                   public String getEmailAddress() {
                        return emailAddress;
                   }
              
                   public void setEmailAddress(String emailAddress) {
                        this.emailAddress = emailAddress;
                   } 
                   
                   @Enumerated(EnumType.STRING)
                   public AccountTypeEnum getAccountType() {
                        return accountType;
                   }
                   public void setAccountType(AccountTypeEnum userRole) {
                        this.accountType = userRole;
                   }
                   
                  // seam-gen attribute getters/setters with annotations (you probably should edit)
                   @Id @GeneratedValue
                  public Long getId() {
                      return id;
                  }
              
                  public void setId(Long id) {
                      this.id = id;
                  }
              
                  @Version
                  public Integer getVersion() {
                      return version;
                  }
              
                  private void setVersion(Integer version) {
                      this.version = version;
                  }
              
              }
              



              Error Log


              15:43:00,641 ERROR [application] javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: org.domain.examgenerator.entity.Category.owner
              javax.faces.el.EvaluationException: javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: org.domain.examgenerator.entity.Category.owner
                   at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
                   at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
                   at javax.faces.component.UICommand.broadcast(UICommand.java:387)
                   at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
                   at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
                   at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
                   at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
                   at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
                   at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
                   at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
                   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
                   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:368)
                   at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
                   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:230)
                   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
                   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
                   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                   at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
                   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
                   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
                   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
                   at java.lang.Thread.run(Unknown Source)
              Caused by: javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: org.domain.examgenerator.entity.Category.owner
                   at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
                   at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:218)
                   at org.jboss.seam.persistence.EntityManagerProxy.persist(EntityManagerProxy.java:137)
                   at org.jboss.seam.framework.EntityHome.persist(EntityHome.java:84)
                   at org.domain.examgenerator.session.CategoryHome.persist(CategoryHome.java:53)
                   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:32)
                   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.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                   at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:97)
                   at org.jboss.seam.util.Work.workInTransaction(Work.java:47)
                   at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:91)
                   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.security.SecurityInterceptor.aroundInvoke(SecurityInterceptor.java:163)
                   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.domain.examgenerator.session.CategoryHome_$$_javassist_seam_4.persist(CategoryHome_$$_javassist_seam_4.java)
                   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.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335)
                   at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:348)
                   at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
                   at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
                   at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
                   at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
                   at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
                   ... 51 more
              Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: org.domain.examgenerator.entity.Category.owner
                   at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
                   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
                   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
                   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
                   at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
                   at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
                   at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
                   at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
                   at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
                   at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
                   at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:212)
                   ... 88 more
              15:43:00,643 WARN  [lifecycle] #{categoryHome.persist}: javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: org.domain.examgenerator.entity.Category.owner
              javax.faces.FacesException: #{categoryHome.persist}: javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: org.domain.examgenerator.entity.Category.owner
                   at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
                   at javax.faces.component.UICommand.broadcast(UICommand.java:387)
                   at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
                   at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
                   at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
                   at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
                   at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
                   at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
                   at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
                   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
                   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:368)
                   at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
                   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:230)
                   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
                   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
                   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                   at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
                   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
                   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
                   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
                   at java.lang.Thread.run(Unknown Source)
              Caused by: javax.faces.el.EvaluationException: javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: org.domain.examgenerator.entity.Category.owner
                   at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
                   at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
                   ... 50 more
              Caused by: javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: org.domain.examgenerator.entity.Category.owner
                   at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
                   at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:218)
                   at org.jboss.seam.persistence.EntityManagerProxy.persist(EntityManagerProxy.java:137)
                   at org.jboss.seam.framework.EntityHome.persist(EntityHome.java:84)
                   at org.domain.examgenerator.session.CategoryHome.persist(CategoryHome.java:53)
                   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:32)
                   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.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                   at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:97)
                   at org.jboss.seam.util.Work.workInTransaction(Work.java:47)
                   at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:91)
                   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.security.SecurityInterceptor.aroundInvoke(SecurityInterceptor.java:163)
                   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.domain.examgenerator.session.CategoryHome_$$_javassist_seam_4.persist(CategoryHome_$$_javassist_seam_4.java)
                   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.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335)
                   at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:348)
                   at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
                   at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
                   at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
                   at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
                   at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
                   ... 51 more
              Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: org.domain.examgenerator.entity.Category.owner
                   at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
                   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
                   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
                   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
                   at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
                   at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
                   at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
                   at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
                   at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
                   at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
                   at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:212)
                   ... 88 more
              
              



              • 4. Re: Session value transient when injected into EntityHome class
                Bernard Labno Master

                I still suspect owner is null and you are looking at some wrong variable. But try playing with @ManyToOne(cascade=CascadeType.ALL) on owner property of Category class.

                • 5. Re: Session value transient when injected into EntityHome class
                  James Domagalski Newbie

                  I have tried your suggestion of playing with the ManyToOne options on the owner property, but it did not resolve the issue.


                  I know that it might seem like it, but I know for sure that I am looking at the correct variable.  What I have posted in my previous post was the instance variable inside the CategoryHome. If my understanding is correct, when the persist is called within CategoryHome, the instance variable is what get persisted to the database.


                  Also as further proof that it is not null is that the code that I have posted in my second post uses entity manager's find and the currentUser variable to get a new persistent version of currentUser.


                  I believe that my issue stems from the fact that I start a new conversation when going into CategoryHome and that is causing my currentUser not to belong to the current persistent context that is within the CategoryHome. I just need any ideas on how to keep the persistent context for currentUser alive during the entire time that it is in the session.


                  Thank you again for your suggestions and your help. 

                  • 6. Re: Session value transient when injected into EntityHome class
                    Bernard Labno Master

                    Once object gets into session scope it becomes detached after request (or conversation) that posted it there is done. Merging brings it back to persistence context. However I've always thought it should not be necessary.