Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Combobox in Listgrid

    Consider the following code for my listgrid...

    ComboBoxItem cbInsurer = new ComboBoxItem("insurer", "Insurer");
    cbInsurer.setOptionDataSource(DataSource.get("insurer_DataSource"));
    cbInsurer.setValueField("insurerId");
    cbInsurer.setDisplayField("insurerName");
    cbInsurer.setDefaultToFirstOption(false);

    ListGridField hInsurer = new ListGridField("insurerId", "Insurer", 100);
    hInsurer.setOptionDataSource(DataSource.get("insurer_DataSource"));
    hInsurer.setDisplayField("insurerName");
    hInsurer.setEditorType(cbInsurer);

    The Record in the listgrid is "Client" and it has an insurerId foreign key to the Insurer table. It's edited using the combobox doing a dynamic lookup in the insurer_DataSource.

    This works fine when I add a client. I save, the attached insurer is displayed etc. The problem comes when I change the insurer by selecting a different item in the combobox. I get the following error....

    "Attempt was made to modify the parent of an object of type ...Client identified by the key Insurer(19001)/Client(1001). Parents are immutable (changed value is Insurer(16001))"

    The Client datasource snippet that defines the foreign key is as follows:


    <field name="insurerId" type="text" title="Insurer" canEdit="true"
    foreignKey="insurer_DataSource.insurerId"/>

    The Client bean field that identifies the relationship is as follows:


    @Column (nullable = true)
    @Extension (vendorName = "datanucleus", key = "gae.parent-pk", value = "true")
    private String insurerId;

    I'm using Google App Engine. Any help with this would be greatly appreciated.

    -Greg

    #2
    Ok, maybe I can ask the question a different way. Can anyone point me to an example (in the Showcase(s) or elsewhere) where there is a combobox populated from the database inside an updatable listgrid?

    Comment


      #3
      Hi,

      GAE is not the same as normal RDB.
      Cause of your problem is the way how GAE handling relations between tables.

      I guess - you have declared many-to-one relation between Client and Insurer tables (in terms of GAE - "owned relation").

      Try browsing your actual database.
      You will notice that table Client does not have column insurer_id - it actually is encoded into primary key of Client. Column insurer_id in your application is calculated on the fly by Datanucleus (persistence provider).

      In GAE all primary key columns are final and can not be changed. So when you change reference - you actually trying to change primary key of the Client entity.
      It is limitation of GAE.

      You can mimic RDB behaviour by removing reference declarations (making "onowned relation"). This way GAE will treat insurer_id as a simple column. But you have to remember actually enforce required relation strategy yourself. For example: remove all related Client entities when Insurer entity removed. One more thing: that way you will loose possibility of transactions.

      For additional information check:
      http://code.google.com/appengine/docs/java/datastore/relationships.html
      http://code.google.com/appengine/docs/java/datastore/transactions.html

      Regards,
      Alius

      Comment


        #4
        Alius,

        Thanks for the reply. I think I can live with those restrictions in my use case. I don't mind enforcing the RI myself. I'm not looking to cascade, anyway - just prevent deletion of a parent with children. GAE sure is different.

        -Greg

        Comment

        Working...
        X