1 Reply Latest reply on May 18, 2006 10:19 AM by Emmanuel Bernard

    The query generated by refresh method

    Jana Parvanova Newbie


      Hello!

      I am using JBoss 4.0.4 RC2.

      I came across the following weird (at least for me) situation:
      I have an entity with a few collection properties such as:


      @Entity
      @Table(name = "t_Site")
      public class Site {

      @OneToMany(mappedBy = "site", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
      @OrderBy(value="day")
      public List getSchedule() {
      return schedule;
      }


      @OneToMany(mappedBy = "site", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
      @OrderBy(value="dateStart")
      public List getZones() {
      return zones;
      }

      }

      At some point in my application these collections are fetched. After this I call EntityManager.refresh and the generated query is:

      select site0_.id as id25_2_,
      site0_.name_bg as name2_25_2_,
      site0_.name_en as name3_25_2_,
      site0_.type_id as type8_25_2_,
      site0_.phonecode as phonecode25_2_,
      site0_.municipality_id as municipa9_25_2_,
      site0_.hasschedule as hassched5_25_2_,
      site0_.postcode as postcode25_2_,
      site0_.eknm as eknm25_2_,
      zones1_.site_id as site4_4_,
      zones1_.id as id4_,
      zones1_.id as id28_0_,
      zones1_.zone_id as zone3_28_0_,
      zones1_.datestart as datestart28_0_,
      zones1_.site_id as site4_28_0_,
      schedule2_.site_id as site6_5_,
      schedule2_.id as id5_,
      schedule2_.id as id26_1_,
      schedule2_.day as day26_1_,
      schedule2_.site_id as site6_26_1_,
      schedule2_.hourstart as hourstart26_1_,
      schedule2_.hourend as hourend26_1_,
      schedule2_.hourendorders as hourendo5_26_1_
      from t_Site site0_, mm_Site_Zone zones1_, t_Site_Schedule schedule2_
      where site0_.id = zones1_.site_id(+)
      and site0_.id = schedule2_.site_id(+)
      and site0_.id = ?
      order by zones1_.datestart asc, day asc

      If I have 1 SiteZone and 2 SiteScheduleDays for a Site, 2 records are returned by the query above and site.getSchedule() has 2 elements while site.getZones() has also 2 (they are the same).

      Is this the proper behaviour or a bug? Am I missing something basic here?

      Any help is highly appreciated!

      Jana Parvanova