0 Replies Latest reply on Feb 5, 2007 10:45 AM by Anne Forumer

    XMLEncoder stops serializing at PersistentBag collection

    Anne Forumer Newbie

      I have this class which is a composite of other classes. One of the composite, Role is itself a composite of class, Recipient. But the XMLEncoder stops at Role designating it as PersistentBag. Apparently, XMLEncoder doesn't go any further because it is not a bean.

      Has anybody developed a persistentDelegate to deal with PersistentDelegate and "unravel" XML all the way to the edge of the object graph?

      Thanks in Advance.


      Here is the "central" class:

      
      public class ServiceNotification implements Serializable
      {
      private long id;
      private List<Role> roles;
      private Application application;
      private Event event;
      private String name;
      
      public ServiceNotification(){}
      public ServiceNotification(Application app, Event event, String name)
      {
      this.application = app;
      this.event = event;
      this.name = name;
      }
      
      @Id
      @GeneratedValue
      public long getId()
      {
      return id;
      }
      public void setId(long id)
      {
      this.id = id;
      }
      
      @OneToOne(fetch = FetchType.EAGER, cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
      public Application getApplication()
      {
      return application;
      }
      public void setApplication(Application application)
      {
      this.application = application;
      }
      
      @OneToOne(fetch = FetchType.EAGER, cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
      public Event getEvent()
      {
      return event;
      }
      public void setEvent(Event event)
      {
      this.event = event;
      }
      
      @OneToMany(fetch = FetchType.EAGER, cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
      public List<Role> getRoles()
      {
      return roles;
      }
      public void setRoles(List<Role> roles)
      {
      this.roles = roles;
      }
      
      
      


      Role contains recipients

      
      public class Role implements Serializable
      {
      private long id;
      private String name;
      private List<Recipient> recipients = new ArrayList<Recipient>();
      
      public Role(){}
      public Role(long id){this.id = id;}
      public Role(String name){this.name = name;}
      
      @Id
      @GeneratedValue
      public long getId()
      {
      return id;
      }
      
      public void setId(long id)
      {
      this.id = id;
      }
      
      /**
      * @return Returns the role_name.
      */
      public String getName()
      {
      return name;
      }
      
      /**
      * @return Returns the recipients.
      */
      @ManyToMany(fetch = FetchType.EAGER, cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
      @JoinTable
      (
      name="ROLE_RECIPIENT",
      joinColumns=@JoinColumn(name="ROLE_ID", referencedColumnName="ID"),
      inverseJoinColumns=@JoinColumn(name="RECIPIENT_ID", referencedColumnName="ID")
      )
      public List<Recipient> getRecipients()
      {
      return recipients;
      }
      
      /**
      * @param recipients The recipients to set.
      */
      public void setRecipients(List<Recipient> recipients)
      {
      this.recipients = recipients;
      }
      
      
      /**
      * @param role_name The role_name to set.
      */
      public void setRole_name(String name)
      {
      this.name = name;
      }
      
      public void setName(String name)
      {
      this.name = name;
      }
      
      
      


      The XML output is:

      
      <?xml version="1.0" encoding="UTF-8"?>
      <java version="1.5.0_06" class="java.beans.XMLDecoder">
      <object class="java.util.ArrayList">
      <void method="add">
      <object id="ServiceNotification0" class="examplen.ServiceNotification">
      <void property="application">
      <object class="examplen.Application">
      <void property="id">
      <long>1</long>
      </void>
      <void property="name">
      <string>FLEET_MANAGER</string>
      </void>
      </object>
      </void>
      <void property="event">
      <object class="examplen.Event">
      <void property="action">
      <string>TO BE DETERMINED</string>
      </void>
      <void property="description">
      <string>An airplane in the database has been changed</string>
      </void>
      <void property="id">
      <long>1</long>
      </void>
      <void property="type">
      <string>AIRPLANE_CHANGE</string>
      </void>
      </object>
      </void>
      <void property="id">
      <long>1</long>
      </void>
      <void property="roles">
      <object class="org.hibernate.collection.PersistentBag">
      <void property="owner">
      <object idref="ServiceNotification0"/>
      </void>
      </object>
      </void>
      </object>
      </void>
      </object>
      </java>