3 Replies Latest reply on Jul 9, 2008 4:51 PM by yacin00

    Persist a List

    yacin00

      Hi
      i have a problem to persist a list


         ... 
          @OneToMany(fetch = FetchType.LAZY)
          @JoinColumn(name ="notificationId")
          private List<Notification> notification;
      ...



      ...
               <h:selectManyCheckbox id="notificat" required="true" value="#{registration.selectedNotifications}" converter="javax.faces.Long">
                  <s:selectItems value="#{notifications}" var="notif" label="#{notif.name}" itemValue="#{notif.notificationId}" />    
               </h:selectManyCheckbox>       
      ...




      ...
         @In(required=false)
         private List<Notification> selectedNotifications;
      ...
       ContactNotification contactNotif = new ContactNotification();   
      ...
      contactNotif.setNotification(selectedNotifications); 
      ...
      em.persist(contactNotif); 
      ...   



      I have a NULL value in the database when I persist, what is wrong?

        • 1. Re: Persist a List
          ericjava.eric.chiralsoftware.net

          What is wrong is, you can't persist a List.


          If the java.util.List class had an @Entity notation on it, you could.  But it doesn't.


          You need to do this some other way.  In particular, you need to create an Entity to contain the list, like:


          @Entity ContactNotifications {
            
            @OrderBy("contactOrderField")
            public List<Contact> getContactList() { ... }
          
          }



          Or, go through the list and persist each ContactNotification one at a time.


          Does it make sense?

          • 2. Re: Persist a List
            yacin00

            hi, sorry,it's somewhat late, But, i found an example which affirm that we can persist a list, i don't know if it works. I'll try...


            My Link
            ???

            • 3. Re: Persist a List
              yacin00

              and it works!!