1 Reply Latest reply on Nov 14, 2004 11:25 AM by jobor

    CMR Collection to ArrayList

    joerage

      Why can't I cast a CMR Collection into an ArrayList?


      private CompanyDetail copyCompanyToDetail(CompanyDetailLocal userLocal) {
       CompanyDetail detail = null;
       try {
       detail = new CompanyDetail();
       detail.setId(userLocal.getId());
       detail.setName(userLocal.getName());
       detail.setUsers((ArrayList)userLocal.getUsers());
       } catch (Exception e) {
       Logger.info("ERROR");
       e.printStackTrace();
       }
       return detail;
       }


      The error is:

      16:03:27,843 INFO [STDOUT] java.lang.ClassCastException
      16:03:27,843 INFO [STDOUT] at com.incycle.platform.entity.company.Company.copyCompanyToDetail(Company.java:84)

      Thanks

        • 1. Re: CMR Collection to ArrayList
          jobor

          I think this is because of the EJB spec.
          All CMR fields are of type Collection or Set.
          You never know the real implementation of the Collection of Set.
          If you want an ArrayList just create one and populate this one with help of the returned Collection or Set.

          Johan.