2 Replies Latest reply on Apr 25, 2007 9:43 AM by Tobias Kilian

    entity-query vs. Manager-nested @Factory List

    Tobias Kilian Newbie

      Hi all!

      I declared the following in components.xml:

      <framework:entity-query name="alleBenutzer" ejbql="select benutzer from BenutzerImpl benutzer" />

      i assumed that this would also do the trick:

      
      @Stateful
      @Scope(ScopeType.SESSION)
      @Name("gruppenManager")
      public class GruppenManagerImpl implements Serializable, GruppenManager {
       @PersistenceContext(type = PersistenceContextType.EXTENDED)
       private EntityManager em;
      
       @DataModel // (scope=ScopeType.PAGE)
       private List<GruppeImpl> gruppenList;
      
       @Factory(value = "gruppenList")
       public void findGruppen() {
       gruppenList = em.createQuery("select gruppe from GruppeImpl gruppe order by id").getResultList();
       }
       ...
      }
      



      I use s:selectItems and s:convertEntity to show the list of Gruppen:

       <h:selectOneMenu id="selectGruppenAuswahl" value="#{selectedBenutzer.gruppe}" required="true">
       <s:selectItems id="gruppenAuswahl" value="#{alleGruppen}" var="gruppeItem" label="#{gruppeItem.label}"/>
       <s:convertEntity />
       </h:selectOneMenu>
      


      however, when using gruppenList instead of alleGruppen as value for s:selectItems the form looks like before, but on submission, i get this well know validation failed error:
      selectGruppenAuswahl is not a valid entry.

      The interesting this is, i get this only if i dont select another entry from the list. In that case i get the "detached entity passed to persist" exception, which happens anyway after the validation is complete. But thats for another posting. The this is the validation gets through if i select another entry.

      I thought the two ways to do the query would be more or less interchangeable.
      I dont know why, but the logged select statements are different for the two options:

      for the framework:entity-query
      11:05:16,984 INFO [STDOUT] Hibernate: select gruppeimpl0_.id as id5_, gruppeimpl0_.name as name5_, gruppeimpl0_.version as version5_, gruppeimpl0_.status as status5_ from gruppen gruppeimpl0_
      11:05:21,734 INFO [STDOUT] Hibernate: select gruppeimpl0_.id as id5_, gruppeimpl0_.name as name5_, gruppeimpl0_.version as version5_, gruppeimpl0_.status as status5_ from gruppen gruppeimpl0_
      


      and for the @Factory solution:
      11:01:42,593 INFO [STDOUT] Hibernate: select gruppeimpl0_.id as id1_, gruppeimpl0_.name as name1_, gruppeimpl0_.version as version1_, gruppeimpl0_.status as status1_ from gruppen gruppeimpl0_
      11:01:44,312 INFO [STDOUT] Hibernate: select gruppeimpl0_.id as id1_0_, gruppeimpl0_.name as name1_0_, gruppeimpl0_.version as version1_0_, gruppeimpl0_.status as status1_0_ from gruppen gruppeimpl0_ where gruppeimpl0_.id=?
      


      I completely dont understand this. But it might be a clue. The first query is done when the page loads, whereas the latter is called when the form is submitted.

      The generated HTML forms also differ in the selection index - the value which the client selects. The ordering is not the same. Could this be a reason?

      Thanks for any help.
      Tobias Kilian