GeoServer: configuring a primary key metadata table for pk assignment using a PostGIS store
<h1>THE ISSUE</h1>
<p>I am following directions <a href="http://docs.geoserver.org/2.1.2/user/data/primarykey.html" rel="nofollow noreferrer">in the GeoServer docs</a> with respect to creating a <em>primary key metadata table</em>, but I am unable to <strong>assign</strong> the primary key of my geographic features (stored in a PostGIS store) using the value of an attribute with the same name in a WFS-t request.</p>
<p>Specifically, I am creating a UUID client-side (this is necessary), and then sending it as the 'uuid' attribute of the WFS-t request XML to GeoServer. Once in GeoServer's hands, I want that UUID to be inserted into the geometry table's primary key column, also named 'uuid'.  What happens instead, is that GeoServer automatically creates its own primary key, something that looks like the following:</p>
<p><code>fid--46a202d5_15320520551_-7ffe</code></p>
<h1>THE CONTEXT</h1>
<p>Here is my geometry table SQL:</p>
<pre><code>CREATE TABLE test_points (uuid VARCHAR(60) PRIMARY KEY NOT NULL);
ALTER TABLE test_points ADD COLUMN title VARCHAR(30) NOT NULL;
ALTER TABLE test_points ADD COLUMN body TEXT NOT NULL;
SELECT AddGeometryColumn('public', 'test_points', 'geometry', '4326', 'POINT', 2);
</code></pre>
<p>Here is my <em>primary key metadata table</em> SQL, basically same as in docs:</p>
<pre><code>CREATE TABLE public.gt_pk_metadata_table (
  table_schema VARCHAR(32) NOT NULL,
  table_name VARCHAR(32) NOT NULL,
  pk_column VARCHAR(32) NOT NULL,
  pk_column_idx INTEGER,
  pk_policy VARCHAR(32),
  pk_sequence VARCHAR(64),
  unique (table_schema, table_name, pk_column),
  check (pk_policy in ('sequence', 'assigned', 'autoincrement'))
);

INSERT INTO gt_pk_metadata_table (
  table_schema,
  table_name,
  pk_column,
  pk_policy
) VALUES (
  'public',
  'test_points',
  'uuid',
  'assigned'
);
</code></pre>
<p>I have had the WFS-t insert operation working correctly (<strong>without</strong> primary key assignment), but here is a representative example of my WFS-t request XML, in case it helps:</p>
<pre><code>&lt;Transaction xmlns=&quot;http://www.opengis.net/wfs&quot; service=&quot;WFS&quot; version=&quot;1.1.0&quot; xsi:schemaLocation=&quot;http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;
  &lt;Insert&gt;
    &lt;test_points xmlns=&quot;my points&quot;&gt;
      &lt;geometry&gt;
        &lt;Point xmlns=&quot;http://www.opengis.net/gml&quot; srsName=&quot;EPSG:3857&quot;&gt;
          &lt;pos&gt;-11828783.001187595 4559315.863154193&lt;/pos&gt;
        &lt;/Point&gt;
      &lt;/geometry&gt;
      &lt;uuid&gt;18984168-27cc-4fc8-8dea-bfbd39c42b22&lt;/uuid&gt;
      &lt;title&gt;A Perfect Example&lt;/title&gt;
      &lt;body&gt;Here's my body.&lt;/body&gt;
    &lt;/test_points&gt;
  &lt;/Insert&gt;
&lt;/Transaction&gt;
</code></pre>
<p>In terms of my GeoServer configuration, on the configuration page of the data store I am using I have the &quot;expose primary keys&quot; flag enabled, and the value of the <em>primary key metadata table</em> parameter is left blank (see below for other values I have tried)</p>
<h1>FAILED ATTEMPTS</h1>
<p>Here is a list of other things I have tried:</p>
<ul>
<li>Creating the geometry table <em>without</em> setting PRIMARY KEY</li>
<li>Creating the geometry table with primary key column of type UUID</li>
<li>Creating the geometry table in a schema other than 'public', keeping the <em>primary key metadata table</em> in the 'public' schema</li>
<li>Creating BOTH the geometry table and the <em>public key metadata table</em> in a schema other than 'public'</li>
<li>Altering the record in the <em>primary key metadata table</em> so that the value in the pk_column_idx column is 0</li>
<li>Altering the record in the <em>primary key metadata table</em> so that the value in the pk_column_idx column is 1</li>
<li>Disabling the &quot;expose primary keys&quot; flag in the store config</li>
<li>Changing the value of the &quot;primary key metadata table&quot; parameter in the store config to the schema qualified name of the metadata table</li>
<li>Changing the value of the &quot;primary key metadata table&quot; parameter in the store config to the <strong>NON</strong>-schema qualified name of the metadata table</li>
</ul>
<p>After each of these changes I deleted the test_points layer and then republished it.  Additionally, I have tried deleting and recreating the store a couple times.</p>
<p>As you can see, I'm getting sort of desperate.  Any help would be very greatly appreciated!</p>
<h1>UPDATE: GeoServer log of insertion</h1>
<p>Great idea iant, I'm sure that may help!  Here is an example of what is logged by GeoServer during an insertion.  Besides the fact that <em>idgen</em> is set to <em>GenerateNew</em>, which I assume is an indication that GeoServer thinks it should generate a new pk, all looks well to me. <strong>But</strong>, this is my first project using GeoServer, so that may not mean much.  A heads up: the UUID, title, body, and geometry are different from the above XML example.</p>
<pre><code>2016-03-01 16:14:29,755 INFO [geoserver.gwc] - DataStoreChange:{/mypoints}test_points PreInsert
2016-03-01 16:14:29,760 INFO [geoserver.gwc] - DataStoreChange: {/mypoints}test_points PostInsert
2016-03-01 16:14:29,763 INFO [geoserver.wfs] - 
Request: transaction
    service = WFS
    version = 1.1.0
    baseUrl = http://127.0.0.1:8080/geoserver/
    group[0] = wfs:insert=net.opengis.wfs.impl.InsertElementTypeImpl@5b886147 (feature: [SimpleFeatureImpl:test_points=[SimpleFeatureImpl.Attribute: uuid&lt;uuid id=fid-4f745b22_1532fc9fb1c_-7ffa&gt;=853596f8-9de1-477a-b287-f3cd114db90a, SimpleFeatureImpl.Attribute: title&lt;title id=fid-4f745b22_1532fc9fb1c_-7ffa&gt;=Another Test, SimpleFeatureImpl.Attribute: body&lt;body id=fid-4f745b22_1532fc9fb1c_-7ffa&gt;=For you!, SimpleFeatureImpl.Attribute: geometry&lt;geometry id=fid-4f745b22_1532fc9fb1c_-7ffa&gt;=POINT (-12044029.67283865 4265797.674539117)]], handle: null, idgen: &lt;unset&gt;, inputFormat: &lt;unset&gt;, srsName: null)
    insert[0]:
        feature[0] = SimpleFeatureImpl:test_points=[SimpleFeatureImpl.Attribute: uuid&lt;uuid id=fid-4f745b22_1532fc9fb1c_-7ffa&gt;=853596f8-9de1-477a-b287-f3cd114db90a, SimpleFeatureImpl.Attribute: title&lt;title id=fid-4f745b22_1532fc9fb1c_-7ffa&gt;=Another Test, SimpleFeatureImpl.Attribute: body&lt;body id=fid-4f745b22_1532fc9fb1c_-7ffa&gt;=For you!, SimpleFeatureImpl.Attribute: geometry&lt;geometry id=fid-4f745b22_1532fc9fb1c_-7ffa&gt;=POINT (-12044029.67283865 4265797.674539117)]
        idgen = GenerateNew
        inputFormat = text/xml; subtype=gml/3.1.1
    releaseAction = ALL
</code></pre>