2 Replies Latest reply on Jun 21, 2007 10:08 AM by ellenzhao

    [1.3.0 Alpha]not-null property references a null or transien

    ellenzhao

      My environment: JBoss As 4.2.0 GA, Seam 1.3.0 CVS June 14th, 2007

      Here the backing bean:

      @Stateful
      @Scope(CONVERSATION)
      @Name("foodNutrients")
      public class FoodNutrientsAction implements Serializable, FoodNutrients {
      
       private static final long serialVersionUID = 366209327813983835L;
      
       @PersistenceContext(type=PersistenceContextType.EXTENDED)
       private EntityManager em;
      
       @DataModel
       private List<FoodWeight> weightUnits;
      
       public void cancel() {
       // TODO Auto-generated method stub
       }
      
       @Remove @Destroy
       public void destroy() {
       // TODO Auto-generated method stub
       }
      
       @Factory("weightUnits")
       public void findWeightUnits() {
       String query = "select w from FoodWeight w where w.food.ndbNo = :foodId";
       this.weightUnits = em.createQuery(query).setParameter("foodId",
       "01001").getResultList();
       }
      }
      


      Here the relevant part in the food-nutrients.xhtml:
      <ui:define name="body">
       <h:messages globalOnly="true" styleClass="message" />
       <rich:panel>
       <f:facet name="header">weight units loading test</f:facet>
       <h:dataTable value="#{weightUnits}" var="unit">
       <h:column>
       <f:facet name="header">
       <h:outputText value="Unit" />
       </f:facet>
       <h:outputText value="#{unit.msreDesc}" />
       </h:column>
       </h:dataTable>
       </rich:panel>
      </ui:define>
      


      Here is the relevant code in the entity class:
      @Entity
      @Name("foodWeight")
      @Scope(CONVERSATION)
      @Table(name = "weight")
      public class FoodWeight implements Serializable {
      
       @Embeddable
       public static class Id implements Serializable {
       private String foodId;
       private String seq;
      
       public Id(String foodId, String seq) {
       this.foodId = foodId;
       this.seq = seq;
       }
      
       public Id() {}
      
       @Column(name = "NDB_No", nullable = false, length = 5)
       public String getFoodId() {
       return foodId;
       }
      
       @Column(name = "Seq", nullable = false, length = 2)
       public String getSeq() {
       return seq;
       }
      
       public boolean equals(Object other) {
       if (this == other) return true;
       if (!(other instanceof Id)) return false;
      
       final Id pk = (Id) other;
      
       return pk.foodId.equals(this.foodId) && pk.seq.equals(this.seq);
       }
      
       public int hashCode() {
       int result;
       result = this.foodId.hashCode();
       result = 7 * result + this.seq.hashCode();
       return result;
       }
      
       public void setFoodId(String foodId) {
       this.foodId = foodId;
       }
      
       public void setSeq(String seq) {
       this.seq = seq;
       }
       }
      
       private Id id;
      
       private Food food;
      
       private String seq;
      
       private String msreDesc;
      
       //other fields....
      
       public FoodWeight() {}
      
       public FoodWeight(Food food, String seq, BigDecimal amount,
       String msreDesc, BigDecimal gmWgt) {
       // set fields
       this.food = food;
       this.seq = seq;
       this.amount = amount;
       this.msreDesc = msreDesc;
       this.gmWgt = gmWgt;
      
       // set identifier values
       this.id.foodId = food.getNdbNo();
       this.id.seq = seq;
      
       // Guarantee referential integrity
       food.getWeights().add(this);
       }
      
       /**
       * @return the food.
       */
       @ManyToOne(targetEntity = Food.class) //@OnDelete(action = OnDeleteAction.CASCADE)
       @JoinColumn(name = "NDB_No", insertable = false, updatable = false, nullable = false)
       public Food getFood() {
       return food;
       }
      
       public void setFood(Food food) {
       this.food = food;
       }
      
       /**
       * @return the composite primary key of this class
       */
       @EmbeddedId
       public Id getId() {
       return id;
       }
      
       public void setId(Id id) {
       this.id = id;
       }
      
       /**
       * @return Description (for example, cup, diced, and 1-inch pieces)
       */
       @Column(name = "Msre_Desc", nullable = false, length = 80)
       public String getMsreDesc() {
       return msreDesc;
       }
      
       public void setMsreDesc(String msreDesc) {
       msreDesc = msreDesc;
       }
      
       /**
       * @return Sequence number
       */
       @Column(name = "Seq", insertable = false, updatable = false, nullable = false, length = 2)
       public String getSeq() {
       return seq;
       }
      
       public void setSeq(String seq) {
       this.seq = seq;
       }
      
       // other getters and setters
      
       /* (non-Javadoc)
       * @see java.lang.Object#hashCode()
       */
       @Override
       public int hashCode() {
       final int prime = 31;
       int result = 1;
       result = prime * result
       + ((amount == null) ? 0 : amount.hashCode());
       result = prime * result + ((food == null) ? 0 : food.hashCode());
       result = prime * result + ((gmWgt == null) ? 0 : gmWgt.hashCode());
       result = prime * result
       + ((msreDesc == null) ? 0 : msreDesc.hashCode());
       result = prime * result + ((seq == null) ? 0 : seq.hashCode());
       return result;
       }
      
       /* (non-Javadoc)
       * @see java.lang.Object#equals(java.lang.Object)
       */
       @Override
       public boolean equals(Object obj) {
       if (this == obj) return true;
       if (obj == null) return false;
       if (!(obj instanceof FoodWeight)) return false;
       final FoodWeight other = (FoodWeight) obj;
       if (amount == null) {
       if (other.getAmount() != null) return false;
       } else if (!amount.equals(other.getAmount())) return false;
       if (food == null) {
       if (other.getFood() != null) return false;
       } else if (!food.equals(other.getFood())) return false;
       if (gmWgt == null) {
       if (other.getGmWgt() != null) return false;
       } else if (!gmWgt.equals(other.getGmWgt())) return false;
       if (msreDesc == null) {
       if (other.getMsreDesc() != null) return false;
       } else if (!msreDesc.equals(other.getMsreDesc())) return false;
       if (seq == null) {
       if (other.getSeq() != null) return false;
       } else if (!seq.equals(other.getSeq())) return false;
       return true;
       }
      }
      
      


      When I was trying to load the food-nutrients.xhtml, I always got this exception:

      Exception during request processing:
      Caused by java.lang.IllegalStateException with message: "Could not commit transaction"
      ...

      Caused by javax.transaction.RollbackException with message: "[com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] Can't commit because the transaction is in aborted state"
      ...

      Caused by javax.persistence.PersistenceException with message: "org.hibernate.PropertyValueException: not-null property references a null or transient value: org.ningning.eatsmart.entity.FoodWeight.msreDesc"
      ...

      Caused by org.hibernate.PropertyValueException with message: "not-null property references a null or transient value: org.ningning.eatsmart.entity.FoodWeight.msreDesc"
      org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
      org.hibernate.event.def.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:263)
      org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:121)
      org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
      org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
      org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
      org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
      org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
      org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:515)
      com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:114)
      com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:249)
      com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:88)
      com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
      com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1256)
      com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
      com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
      org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:140)
      org.jboss.seam.transaction.UTTransaction.commit(UTTransaction.java:35)
      org.jboss.seam.jsf.AbstractSeamPhaseListener.commitOrRollback(AbstractSeamPhaseListener.java:285)
      org.jboss.seam.jsf.TransactionalSeamPhaseListener.handleTransactionsAfterPhase(TransactionalSeamPhaseListener.java:45)
      org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:106)
      com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:280)
      com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
      javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
      org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:70)
      org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:81)
      org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:56)
      org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:62)
      org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:56)
      org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:47)
      org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:56)
      org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:293)
      org.jboss.seam.web.AbstractAjax4jsfFilter.doFilter(AbstractAjax4jsfFilter.java:35)
      org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:56)
      org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:64)
      org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:56)
      org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:127)
      org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:127)
      org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:277)
      org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
      org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
      org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
      org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
      org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
      org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      java.lang.Thread.run(Thread.java:619)

      I wrote the code according to the example 1.11 described in user manual, mine is a simplified version, just want to see if the FoodWeight can be loaded correctly given a foodId. I read the user manual and Michael Yuan's Seam book in order to get a clue, but failed to figure out what was wrong. I tried to let entityManager first load a food entity and then use food.getFoodWeights(), that worked perfectly. But I desparately want to know why the code above does not work and how to correctly use this way of data fetching with Seam......Any enlightenment would be highly appreciated!


      Regards,
      Ellen


        • 1. Re: [1.3.0 Alpha]not-null property references a null or tran
          ellenzhao

          Oh I forgot the mention that in the database, there is simply no null-value in the msreDesc column. And I just modified this code:

          // Guarantee referential integrity
           food.getWeights().add(this);
          


          in the FoodWeight entity class to:
          // Guarantee referential integrity
           food.getWeights().add(this);
           this.setFood(food);
          


          rebuilt and tested, did not help at all.

          • 2. Re: [1.3.0 Alpha]not-null property references a null or tran
            ellenzhao

            Bug fixed: the line in the entity bean:

            public void setMsreDesc(String msreDesc) {
             msreDesc = msreDesc;
            }
            


            should be
            public void setMsreDesc(String msreDesc) {
             this.msreDesc = msreDesc;
             }
            


            This is really grievous and the bug was hard to track...Finally eclipse's yellow warning "this assignment has no effect" caught my attention, I added a "this." and things are working.