1 Reply Latest reply on Sep 23, 2004 5:05 AM by garyjones

    CMR Field Type of Collection in JBoss

    jonefun

      Hi I have a question ?
      I Have to Entities LayoutTemplate and SlotTemplate. A LayoutTemplate can have 1-N SlotTemplates. The relationship between the two entities is a Many-Many and both cmf-field-type values have been set to Collection.

      The spec 2.1 EJB says that a Collection will allow duplicates therefore I should be able to create a SlotTemplate entity and add it to the LayoutTemplate's slotTemplates collection twice. But I can *not*. When I check the Collection implementation provided by JBOSS it creates a org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet aka SET even when I choose java.util.Collection as the cmr-field-type and does not allow me to add duplicate entities to the collection.

      Am I doing something wrong or is JBoss wrong when it provides me with a RelationSet when I asked for a java.util.Collection (type) implementation.

      Any help would be much appreciated

        • 1. Re: CMR Field Type of Collection in JBoss
          garyjones

          The spec is ambiguous on the reason for having Set and Collection in CMR fields. It DOES NOT indicate why you sould use one over the other.

          It also does NOT indicate that using a Collection should allow duplicate entries. However, it does NOT indicate that you can't have duplicate entries.

          Therefore the JBoss group have interpreted this in their own way. Wrongly in my opinion.

          The reason I say wrongly is two fold:
          1. In Java Sets are used as a collection of unique values. Other Collection implementations allow duplicate entries. Why bother with the distinction otherwise.


          2. The EJB spec describes how Set and Collection are used for exactly this reason in "select" methods. Set used for unique entries and Collection allows duplicates. If I was interpreting the spec I would apply this same logic to the relationship fields.

          Clearly the spec needs clarification on this point, but in the meantime why not just allow the developer the choice of how their beans should behave.

          JBoss have now restricted the use of CMR fields to just Set. If the spec ever clarifies the use of Set and Collection to allow duplicates in Collection then JBoss will need to change their code.