glassfish
  1. glassfish
  2. GLASSFISH-556

Spec Violation: TopLink expects my collection field/property to be Cloneable

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 9.0pe
    • Fix Version/s: not determined
    • Component/s: entity-persistence
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      556
    • Status Whiteboard:
      Hide

      HIGH

      Show
      HIGH

      Description

      I have two Entities called A & B. B has a OneToMany reln with A as the following
      code snippet shows:

      @Entity public class B {
      @Id String id;
      @OneToMany private List<A> foo = new ArrayList<A>();
      public List<A> getFoo()

      { return foo; }

      public void setFoo(List<A> foo)

      { this.foo = foo; }

      ...
      }

      In my main program (Test.java), if I use pass a List which is not Cloneable to
      B.setFoo(), then during commit time, I get following exception:

      Exception Description: The method invocation of the method [protected native
      java.lang.Object java.lang.Object.clone() throws
      java.lang.CloneNotSupportedException] on the object [[pkg.A id = sahoo]], of
      class [class java.util.Arrays$ArrayList], triggered an exception.
      Internal Exception: java.lang.reflect.InvocationTargetException
      Target Invocation Exception: java.lang.CloneNotSupportedException:
      java.util.Arrays$ArrayList

      In my code, this is how I am trying to call setFoo()...
      em.getTransaction().begin();
      String id = args[0];
      A a = new A(id);
      B b = new B(id);
      if(Boolean.getBoolean("USE_ARRAYS_ASLIST"))

      { b.setFoo(java.util.Arrays.asList(a)); }

      else

      { List<A> temp = new ArrayList<A>(); temp.add(a); b.setFoo(temp); }

      em.persist(a);
      em.persist(b);
      em.getTransaction().commit();

      When I run this program with -DUSE_ARRAYS_ASLIST=true, I get that exception.
      Otherwise, it works. If you look at implementation of Arrays.asList(), it
      returns a List which is not Cloneable.

      Complete test case is attached here with.

      – Sahoo

        Activity

        Hide
        gfbugbridge added a comment -

        <BT6443395>

        Show
        gfbugbridge added a comment - <BT6443395>
        Hide
        marina vatkina added a comment -

        Nice to fix but can wait until 9.1

        Show
        marina vatkina added a comment - Nice to fix but can wait until 9.1
        Hide
        ijuma added a comment -

        Adding myself to cc list.

        Show
        ijuma added a comment - Adding myself to cc list.
        Hide
        pkrogh added a comment -

        Reprioritized based on BUG triage. P4 HIGH.

        Show
        pkrogh added a comment - Reprioritized based on BUG triage. P4 HIGH.
        Hide
        Tom Mueller added a comment -

        Bulk change to set fix version to "not determined" where the issue is open but the value is for a released version.

        Show
        Tom Mueller added a comment - Bulk change to set fix version to "not determined" where the issue is open but the value is for a released version.

          People

          • Assignee:
            tware
            Reporter:
            Sanjeeb Sahoo
          • Votes:
            2 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: