Announcement Announcement Module
Collapse
No announcement yet.
Fetching eagerly on Lists 1:n Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Fetching eagerly on Lists 1:n

    I have the following entities (simplified to illustrate):

    Code:
    class Profile {
       @OneToMany(cascade = CascadeType.ALL)
       List<Setting> settings = new ArrayList<Setting>();
       // other properties
    }
    
    class Setting {
       @ManyToOne
       SettingDefinition definition;
       // other properties
    }
    
    class SettingDefinition {
       // some properties - no relationships defined here
    }
    When the list of Profiles is displayed on a GWT UI, all its properties are displayed fine. But the list of settings, have nulls for their definitions even if they do have non-null definitions referenced (I checked the db). I tried specifying this in the Setting entity:

    Code:
    @ManyToOne(fetch=FetchType.EAGER, optional=false)
    and also increasing the hibernate.max_fetch_depth to more than three (AFAIK, 3 is the default), but I can't get the Setting entities from containing their corresponding Definition entities when they come from the server.

    Is there any way to force these properties being fetched?

    using Roo 1.2.1 with jpa ActiveRecord, hibernate, postgresql, gwt on ubuntu 11.04.

  • #2
    I am not too familiar with Roo, only played with it once but can likely help you here. A couple of questions first:

    a) Do you have access to your DAO? Are you the one creating it or is Roo auto-generating it for you? If Roo is, can you please post the DAO here?

    b) Enable debug in hibernate and capture the query being generated.

    Best regards,

    Alfredo

    Comment


    • #3
      a) DAOs, or EntityProxies, are generated by Roo's GWT plugin. They all look like this (their implementations are created upon gwt-compilation, and I took out fully-qualified class/interface names):

      Code:
      @ProxyForName(value = "Profile", locator = "ProfileLocator")
      @RooGwtProxy(value = "Profile", readOnly = { "version", "id" }, scaffold = true)
      public interface ProfileProxy extends EntityProxy {
      
          abstract Long getId();
          abstract String getName();
          abstract void setName(String name);
          abstract Integer getVersion();
          abstract List<SettingProxy> getSettings();
          abstract void setSettings(List<SettingProxy> settings);
          // other abstract setters/getters...
      }

      b) This is the query (setting is really boardsetting and profile is boardprofile):
      Code:
      select settings0_.board_profile as board1_13_2_, settings0_.settings as settings2_, boardsetti1_.id as id8_0_, boardsetti1_.definition as definition8_0_, boardsetti1_.setting_value as setting2_8_0_, boardsetti1_.version as version8_0_, boardsetti2_.id as id9_1_, boardsetti2_.address as address9_1_, boardsetti2_.category as category9_1_, boardsetti2_.name as name9_1_, boardsetti2_.register as register9_1_, boardsetti2_.version as version9_1_ from trucklink.board_profile_settings settings0_ inner join trucklink.board_setting boardsetti1_ on settings0_.settings=boardsetti1_.id inner join trucklink.board_setting_definition boardsetti2_ on boardsetti1_.definition=boardsetti2_.id where settings0_.board_profile=?

      Thanks for your help.

      Comment


      • #4
        I see. Take a look at the response provided by Thomas and Jen in the forum. It seems that in this case you need to call another method to fetch the association since you are using Roo. Something similar to what they suggested in the forum would have been the case with hibernate using "alias" in this case. You would have had to pass the "settings.settingDefinition" when fetching using alias.

        Best regards,

        Alfredo

        Comment


        • #5
          Thanks Alfredo.

          For the record, I cross-posted this issue to the gwt group, and there the solution was given:

          In my ProfileDetailsActivity (or whatever Activity or Presenter where you want this data), I needed to add explicitly "settings.definition", so it ends up looking like this:

          Code:
          protected void find(Receiver<com.google.web.bindery.requestfactory.shared.EntityProxy> callback) {
                  requests.find(proxyId).with("settings", "settings.definition").fire(callback);
          }

          Comment


          • #6
            Awesome, yeah that makes sense. It would have looked very similar with hibernate and the use of alias.

            Glad you got it all sorted out and working.

            Best of luck.

            Alfredo

            Comment

            Working...
            X