7 Replies Latest reply on Feb 16, 2007 3:29 PM by Leo Baschy

    EntityHome persist problem

    Dustin Norlander Apprentice

      I am having trouble getting a simple object to persist.

      here is the form

       <h:outputLabel for="name">Group Name:</h:outputLabel>
       <h:inputText id="name" value="#{uGroup.name}" />
       <s:message />
       <h:selectOneListbox value="#{uGroup.ugrouptype}">
       <s:selectItems value="#{groupTypes}" var="ugrouptype"
       label="#{uGroupType.name}" noSelectionLabel="Please Select..." />
       <ec:convertEntity />
       <h:commandButton value="Save" action="#{groupHome.persist}"
       styleClass="button" />

      And here is my entity home.

      public class GroupHome extends EntityHome<UGroup> {
       @In (required=true)
       private User user;
       public UGroup initGroup() {
       return this.getInstance();
       protected UGroup createInstance() {
       System.out.println("Creating a ugroup");
       UGroup g = new UGroup();
       return g;

      and my entity looks like

      @Table(name = "UGroup")
      public class UGroup implements java.io.Serializable {
       // Fields
       private int id;
       private User user;
       private String name;
       private UGroupType ugrouptype;

      So when I fill in the fields of the form and press save, it just reloads the page. I can see it creates a new ugroup, but persist is never called. Am I doing something wrong?


        • 1. Re: EntityHome persist problem
          Leo Baschy Novice

          While I didn't look close enough to determine whether there are other problems, from my own experience I know sooner or later you could run into a problem with that factory being invoked only once in a conversation, and hence your factory made instance not being the same as the one home uses.

          Hence, while you still may be having another problem, one first change I'd make is to forget about that advice in the reference manual to use the shorter syntax with a factory made instance, and rather than


          instead use the longer but always correct syntax


          Then go find your remaining problems, if any.

          • 2. Re: EntityHome persist problem
            Pete Muir Master

            Put a h:message component on the selectOneListbox (or better still keep a h:messages component running for the whole page during devel) and check what validation/update/conversion errors you are getting.

            And I've never had a problem with the style the ref manual recommends for EntityHome's and factories

            • 3. Re: EntityHome persist problem
              Dustin Norlander Apprentice

              Great advice thanks

              The error I am getting is:

              Invalid selection. Selected item cannot be loaded from persistence context

              What is the prefered way to keep the select items in the same persistence context as the EntityHome? In the entityconverter example I can't see where
              clientTypes.resultList comes from.. ?


              • 4. Re: EntityHome persist problem
                Pete Muir Master

                1) Make sure you are in a conversation

                2) components.xml IIRC

                but that error is more serious and means the entityconverter hasn't been able do its job. Make sure you are using 1.1.6 not 1.1.5. Are you getting that error when you don't select an option?

                • 5. Re: EntityHome persist problem
                  Dustin Norlander Apprentice

                  Thanks for the tips.

                  I am using 1.1.6 and I don't get that error when nothing is selected. Any other suggestions on how to debug this? Oh, and I am using Icefaces 1.5.3..

                  thanks much,

                  • 6. Re: EntityHome persist problem
                    Leo Baschy Novice


                    To get the problem I saw you need to do this as I got to do when I started from a seam-generated project a couple weeks ago (things changed in seam-gen since, I think now there is join instead of begin):

                    From a list view (with query) go to create new entity page with a propagation begin, then with a link that doesn't end the conversation (someone else on the project put a tree of top level commands into a div for all pages) go somewhere else, soon through links come to the list again (but not "back", just following links as usual), at which time you still have the same conversation that "began", go to create new entity page (with same propagation begin), and you have a problem. For the heck of it put the id of the factory made instance up next to the id of the home.instance and they were different! I saw it. I repeated it. Why a new home? I'm not sure. But why not a new factory made instance? I guess the one from when the conversation began last time here still was around, so no call to factory method.

                    My solution was twofold:

                    1) I stopped using the factory made instance.

                    2) I for now don't go there with a propagation begin. I'm still trying to get a full understanding of what I'll want to do with conversations. Let's say I'm in a conversation to do something, what are all the possible ways out, and how to I get 100% certainty of behavior at all possible exits. That should include a team member putting "any kind of non-seam aware link" into a part of the page that I just include, or "almost any kind of link".

                    I've mentioned this before in http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4010984

                    • 7. Re: EntityHome persist problem
                      Leo Baschy Novice

                      Not sure about all the details now, but the problem was real. I clearly had it display in the view fields from the factory made instance and from the home.instance, and they were two separate instances. I showed the screen to a colleague. Since I've stopped using the factory made instance I don't have that kind of problem any more. And it probably was made more frequent of a problem because of use of propagation begin without matching end.