Announcement

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

    Hibernate ds.xml Composite Key

    I use a Hibernate datasource with a table that has a composite primary key. I've set the idClassName and data is correctly queried with autoDeriveSchame="true". However, If I want to mark the primary key fields as hidden="true", what name do I use when referring to them in the fields list? Here's my ds.xml:

    Code:
    <DataSource ID="OpeningTag"
                serverType="hibernate"
                beanClassName="com.assaabloy.protech.domain.OpeningTag"
                idClassName="com.assaabloy.protech.domain.OpeningTagId"
                autoDeriveSchema="true"
                dropExtraFields="true"
                configBean="protechSessionFactory"
                xmlns:fmt="WEB-INF/">
    </DataSource>
    From the dev console, I see the IDs in the response look like:

    Code:
    {
      data:[
        {
          id_openingId: 2,
          id_tagId: 2
        }
      ],
    }
    If I call out either "id_openingId" or "id_tagId" as fields, they no longer get returned in the response. What name am I supposed to use for these fields?

    #2
    It looks like you may have hand-edited the sample of data from the console, as the actual data returned for a composite key should have another layer of nesting - and unfortunately this means you’ve removed the part of the data that shows the right fieldName to use!

    And we neither the bean nor the real data, we have no way of guessing the name..

    There are other simple ways to see the derived fields however, such as by simply calling getFields() on the DataSource, or just looking at the data returned by the DataSourceLoader (which is easily read JSON), or, since you seem to be trying to make sure it doesn’t appear, you may already be seeing it in a ListGrid, and hence the name is visible there also.

    Comment


      #3
      Here's the full response:

      Code:
      {
          affectedRows:0, 
          data:[
              {
                  id_openingId:2, 
                  id_tagId:2, 
                  modifiedTime:"2019-04-12T18:46:47.000", 
                  createdBy:2, 
                  createdTime:"2019-04-12T18:46:47.000", 
                  modifiedBy:null
              }
          ], 
          endRow:1, 
          invalidateCache:false, 
          isDSResponse:true, 
          operationType:"fetch", 
          queueStatus:0, 
          startRow:0, 
          status:0, 
          totalRows:1
      }

      Comment


        #4
        That’s still an unexpected format for a composite key. The next step is to look at the other information we recommended that you take a look at, and share it with us if you need further help.

        Comment


          #5
          The name in the returned data is "id_openingId" and in the list grid it's "Id Opening Id".

          Here's the output from the datasourceloader:

          Code:
          if (window.isc == undefined || window.isc.DataSource == undefined) {
              alert("Can't load DataSources - SmartClient runtime not loaded");
          }
          isc.DataSource.create({
              autoDeriveSchema: true,
              allowAdvancedCriteria: true,
              idClassName: "com.assaabloy.protech.domain.OpeningTagId",
              inheritsFrom: isc.DataSource.create({
                  extIsEmbeddedId: true,
                  allowAdvancedCriteria: true,
                  idClassName: "com.assaabloy.protech.domain.OpeningTagId",
                  entityName: "com.assaabloy.protech.domain.OpeningTag",
                  serverType: "hibernate",
                  dropExtraFields: true,
                  ID: "OpeningTag_inheritsFrom",
                  generatedBy: "v11.1p_2018-08-01/PowerEdition Deployment 2018-08-01",
                  fields: [{
                      validators: [],
                      canEdit: true,
                      name: "id_openingId",
                      length: 255,
                      valueXPath: "id/openingId",
                      type: "integer",
                      required: true,
                      primaryKey: true
                  }, {
                      validators: [],
                      canEdit: true,
                      name: "id_tagId",
                      length: 255,
                      valueXPath: "id/tagId",
                      type: "integer",
                      required: true,
                      primaryKey: true
                  }, {
                      name: "createdBy",
                      length: 255,
                      type: "integer",
                      required: false,
                      validators: [],
                      canEdit: true
                  }, {
                      name: "createdTime",
                      length: 19,
                      type: "datetime",
                      required: false,
                      validators: [],
                      canEdit: true
                  }, {
                      name: "modifiedBy",
                      length: 255,
                      type: "integer",
                      required: false,
                      validators: [],
                      canEdit: true
                  }, {
                      name: "modifiedTime",
                      length: 19,
                      type: "datetime",
                      required: false,
                      validators: [],
                      canEdit: true
                  }]
              }),
              serverType: "hibernate",
              dropExtraFields: true,
              ID: "OpeningTag",
              fields: [{
                  hidden: true,
                  name: "id_openingId",
                  validators: []
              }]
          })

          Comment

          Working...
          X