0 Replies Latest reply on Jan 19, 2011 6:42 AM by John Strandmyr

    onetomany problem with null values in arraylist

    John Strandmyr Newbie

                     Hi, this is my first post, so i hope im doing this right.

       

      I have three entities that belong in a hiarchy. The entities are Prosess, ProsessTrinn and ProsessTrinnFare

       

       

      defined in Prosess is:

       

      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)

      @JoinColumn (name="prosess_id")

      public List<ProsessTrinn> prosessTrinn = new ArrayList<ProsessTrinn>();

       

      This works fine.

       

      In ProsessTrinn I have:

       

      @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER)

      @JoinColumn (name="prosesstrinn_id")

      @IndexColumn(name="id")   

      public List<ProsessTrinnFare> farer = new ArrayList<ProsessTrinnFare>();

       

      What happens is that all data is loaded, but a lot of null values are inserted in each of the arraylists. If i have 1 Prosess, 4 ProsessTrinn and each of those have 1 ProsessTrinnFare each, it results in 1, 2, 3 and 4 null values in the ArrayList. It may seem like the last entity to be loaded is inserted by index, and not reseting index for each of the Arraylists, causing there to be 1, 2, 3 and 4 null-values.

       

      I know i can loop the arraylist on the getter, and remove null-values but seems like i've done something wrong and i'd rather correct that.

       

      I'd apprechiate any hints and tips