Yep this is a pain, only a few implementations support user defined feature ids.

There are two things:
- check the capabilities of the datastore to see if it supports this functionality
- use a "user data" hint to enable the extra functionality

Here is the example from the documentation:

if( featureStore.getQueryCapabilities().isUseExisingFIDSupported() ){
    // featureStore allows us to create our own featureIDs
    SimpleFeatureBuilder b = new SimpleFeatureBuilder(featureStore.getSchema());
    DefaultFeatureCollection collection = new DefaultFeatureCollection(null,featureStore.getSchema());

    String typeName = b.getFeatureType().getTypeName();
    for( FeatureIterator iter=features.features(); iter.hasNext(); ){
        SimpleFeature feature = (SimpleFeature) iter.next();

        b.init( feature ); // take feature into a builder to modify
        b.featureUserData(Hints.USE_EXISTING_FID, Boolean.TRUE);
        feature = b.buildFeature( typeName+"."+System.currentTimeMillis() );

        collection.add( feature );
    }
    featureStore.addFeatures(collection);
}
else {
   // allow featurestore to create featureIDs
   featureStore.addFeatures( features );
}
And the link:

http://docs.geotools.org/latest/userguide/library/data/featuresource.html#adding-data

-- 
Jody Garnett

On Monday, 3 December 2012 at 10:38 PM, Fritz Richter wrote:

Hi together,
I'm playing around now for hours an simply can not make it run.

I try to store a feature into postgis, which is almost working perfectly, except the feature id.

Polygon polygon = GisUtils.convertToPolygon(tile);
builder.set("updated", new Date());
builder.set("geom", polygon);
...
SimpleFeature feature = builder.buildFeature(featureId);

In my case the featureID is set to "18/12/12". When I look into the database table, the id looks like this "fid--50250c12_13b60c20cc4_-7061".
I really do not know, why my featureId is not used but the stange id appears.

Any help?

My db definition looks like this:
CREATE TABLE result
(
  tile_id text NOT NULL,
  updated timestamp without time zone NOT NULL,
  geom geometry,
...
  CONSTRAINT pk_result PRIMARY KEY (tile_id ),
  CONSTRAINT enforce_dims_geom CHECK (st_ndims(geom) = 2),
  CONSTRAINT enforce_geotype_geom CHECK (geometrytype(geom) = 'POLYGON'::text OR geom IS NULL),
  CONSTRAINT enforce_srid_geom CHECK (st_srid(geom) = 4326)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE result
  OWNER TO postgres;


------------------------------------------------------------------------------
Keep yourself connected to Go Parallel:
BUILD Helping you discover the best ways to construct your parallel projects.
http://goparallel.sourceforge.net
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users