-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Entering data in null component, how?
PostPosted: Fri Jul 27, 2007 5:37 am 
Newbie

Joined: Tue Jun 28, 2005 10:20 am
Posts: 15
Hello,
i do have an embeddable component:

Code:
@Embeddable
public class TGWSample implements java.io.Serializable {

    private Float sampleSize;      //no of grains in sample
    private Float sampleWeight;  // weight of sample in gramm
    private Float tgw;                //thousand grain weight in gramm
[..getter and setter removed]
}

This component is integrated into several classes. Also there is a manager which calculates tgw out of sampleSize and SampleWeight.
This all works great, if and only if at least one attribute from TGWSample is not null.

My problem: The data for TGWSample should be entered by the user. So at the beginning all attributes are null.
There is an exception about
Code:
<h:inputText size="5" value="#{plot.tgwSample.sampleSize}

which states that plot.tgwSample returns null and sampleSize is not reachable.(PropertyNotFound)
According to [Java Persistence with Hibernate Page 189] a component will be mapped in the owning entity as null, when all its attributes are null. This explains the exception.
My question: how can the user enter data for suchg a component?
Of course, if there is only one entity, it could be backed by a bean (and this bean can easily create the missing component)
But i do have a datatable shown and entering data should happen inside it.
Do you know a way of achieving this?
Ciao,
Carsten


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 27, 2007 6:52 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
You could implement Plot in a way that TGWSample is never null.

i.e.
Code:
public class Plot {

  private TGWSample tgwSample = new TGWSample();

  public TGWSample getTGWSample() {
    return tgwSample;
  }

  public void setTGWSample (TGWSample tgwSample) {
    if (tgwSample == null) {
      this.tgwSample = new TGWSample();
    } else {
      this.tgwSample = tgwSample;
    }
  }
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 27, 2007 7:32 am 
Newbie

Joined: Tue Jun 28, 2005 10:20 am
Posts: 15
Thanks for the answer. But this is only half the way:-(
Now i am getting an other exception. Plot is the owning entity for TGWSample.
The exception comes up, even when only readonly fields are displayed. The exception has nothing to do with my inputs. It seems Hibernate doesn't like the not null empty component:-(
Code:
13:23:33,093 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_2] TwoPhaseCoordinator.beforeCompletion - failed for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@7d72df
javax.persistence.PersistenceException: org.hibernate.validator.InvalidStateException: validation failed for: de.bafz.aveq.field.model.Plot
   at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:527)
   at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:114)
   at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:249)
   at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:88)
   at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
   at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1256)
   at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
   at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
   at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:140)
   at org.jboss.seam.transaction.UTTransaction.commit(UTTransaction.java:47)
   at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:579)
   at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:325)
   at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:226)
   at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:184)
   at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:280)
   at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
[...]
Caused by: org.hibernate.validator.InvalidStateException: validation failed for: de.bafz.aveq.field.model.Plot
   at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:143)
   at org.hibernate.validator.event.ValidateEventListener.onPreUpdate(ValidateEventListener.java:172)
   at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:217)
   at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:65)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
   at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:515)
   ... 51 more



Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 27, 2007 9:46 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
In my simple test case I can add and update Plots no problem. What annotaed constraints are defined on Plot and TGWSample?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 30, 2007 4:59 am 
Newbie

Joined: Tue Jun 28, 2005 10:20 am
Posts: 15
Thanks. Perhaps it is the environment?(Seam,2.0Beta JBOss AS4.2)
The getters in TGWsample where copied directly from Plot(here they are working) I will investigate further and report back.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.