2 Replies Latest reply on Jul 31, 2006 9:17 AM by Scott Balmos

    Using entities with collections?

    Scott Balmos Newbie

      Hi all,

      In 1.0.2, the WSDL generator now ignores datatypes that are collections. This was easy enough to fix with my wrapper SOAP interface. However, the complex datatypes that I return from my functions are entity beans, which themselves have member collections. I cannot replace these collections with arrays, since the EJB3 Persistence system needs collections to determine relationship mappings. And I can't create overridden getter methods in the entities that return arrays.

      So, what am I supposed to do? On one hand, I must use collections in the entities for the persistence framework. Yet on the other hand, I can't for the SOAP framework. Am I supposed to create new wrapper entity datatypes for SOAP, which only use arrays? What about Map-type collections, where a flat array wouldn't really work?

      Ideas are appreciated.

      --Scott

        • 1. Re: Using entities with collections?
          Frank Heldt Newbie

          Here's what i did: The entity bean is field mapped and the getters/setters convert between Collection and Array.

          A sample:

          public class MyEntityBean implements java.io.Serializable {
           @Id
           @Column(name="id")
           private int id;
           ...
           @OneToMany(mappedBy = "abc")
           private Set<ColumnHeader> colHeaders;
           ...
           public ColumnHeader[] getColumns() {
           return this.colHeaders.toArray(new ColumnHeader[ this.colHeaders.size() ]);
           }
           public void setColumns(ColumnHeader[] colHeaders) {
           this.colHeaders.clear();
           for (int i = 0; i < colHeaders.length; i++) {
           this.colHeaders.add(colHeaders[ i ]);
           }
           }
          }
          


          • 2. Re: Using entities with collections?
            Scott Balmos Newbie

            Groan... Nothing like rewriting all those getters/setters, the annotations, etc. :) I'm guessing there's no real difference in using property vs field annotations.

            What's worse is that some of my entities use Map-type collections, which there is no support at all for (I thought SOAP had some key-value type primitive???). I have no idea how I am going to fix that. I thought about writing XmlAdapters, like in http://weblogs.java.net/blog/kohsuke/archive/2005/04/xmladapter_in_j.html , but I just tried that. The WSDL generator doesn't pick up on the adapter, and continues to almost-silently ignore the Map.

            Ideas for that one would be even more appreciated. Thanks!

            --Scott