3 Replies Latest reply on Aug 10, 2006 3:00 AM by baz

    Managed(Hibernate)Entity usage question

    baz

      Hello,
      i do have 2 Manged Entitys set up:

      <component name="bazProject" class="org.jboss.seam.core.ManagedHibernateEntity">
       <property name="entityClass">de.bafz.lims.model.Project</property>
       <property name="session">#{bazDatabase}</property>
       <property name="id">#{bazProjectID}</property>
       <property name="idClass">java.lang.String</property>
       </component>
       <component name="bazExperiment" class="org.jboss.seam.core.ManagedHibernateEntity">
       <property name="entityClass">de.bafz.lims.model.Experiment</property>
       <property name="session">#{bazDatabase}</property>
       <property name="id">#{bazExperimentID}</property>
       <property name="idClass">java.lang.Long</property>
       </component>
      

      I can use bazProject as expected. i define an attribute like so
      @Out(required=false,scope=ScopeType.SESSION)
       String bazProjectID;
      

      and in a method of my bean bazProjectID is set.


      But with bazExperiment i have trouble.
      1. question
      What type must the bazExperimentID be?
      I suppose java.lang.String

      @Out(required=false,scope=ScopeType.SESSION)
       private String bazExperimentID;
      

      setting the attribute like so
      bazExperimentID=getExperiment().getId().toString();


      After this bazExperimentID is in the session but accessing bazExperiment is ever null. Debuging my app tell me that getInstance from Managed(Hibernate)Entity is never called.

      What is wrong with bazExperiment?
      The only difference is that bazProject is used in an html page while bazExperiment is not.
      Ciao,
      Carsten

        • 1. Re: Managed(Hibernate)Entity usage question
          baz

          Hello,

          The only difference is that bazProject is used in an html page while bazExperiment is not.

          That is the difference.
          I accessed bazExperiment in a html page and..
          voila it is injected.

          If i do not access such a component in a html page it won't be injected.
          Gavin can you help?

          Ciao,
          Carsten

          • 2. Re: Managed(Hibernate)Entity usage question
            gavin.king

            For a start, you should not convert the id to a string.

            Second, make sure that the outjection actually *happens*.

            • 3. Re: Managed(Hibernate)Entity usage question
              baz

              Hello,
              Thanks for your answer.

              you should not convert the id to a string.

              if i do not convert, i get a class cast exception. This is due to this codefragment from getInstance
              return (Serializable) idConverter.getAsObject(
               facesContext,
               facesContext.getViewRoot(),
               >>>> (String) id <<<<<<<<<
               );
              


              But i have solved my problem. The component does not exist when i do not use it in an html page. So i have to use create=true :-) when i inject the component.
              Ciao,
              Carsten