In that case, I would like to make known to you, that there is some strange behaviour in GeoTools.
When connecting to SqlServer and using the GT_PK_METADATA facility with the sequence policy, the SqlServer dialect consistently fails to get a new primary key, and does not even try to call the named database sequence. Thus no insert will ever work. I validated with logging set to FINEST. Example (approx): create sequence my_seq as BIGINT ; create table foo ( id BIGINT PRIMARY KEY , geom geometry ); insert into GT_PK_METADATA( 'schema' , 'foo' , 'id' , null , 'sequence' , 'my_seq' ); Pseudocode: feature_source.addFeatures( [ foo_feature ] ) https://hub.docker.com/_/microsoft-mssql-server could perhaps help in reproduction of the issue. yours acefael On Tue, Dec 14, 2021 at 07:10:35AM -0800, Jody Garnett wrote: > Can you submit your change as a pull request please, we have contributing > guidelines online for participation in the project covering what is needed. > > In the specific case of SQLServer not many developers have access to a > database to test against. I know I do not … > > Jody > > On Mon, Dec 13, 2021 at 1:10 PM acefael <e...@acefael.es> wrote: > > > hi, > > > > the default implementation of SQLDialect returns null for any invocation > > of getNextSequenceValue and SQLServerDialect does not override that. > > Therefore using GT_PK_METADATA with pk_policy 'sequence' will never work. > > Could anyone with enough access apply my implementation of > > getNextSequenceValue to SQLServerDialect ? > > > > My implementation > > > > @Override > > public Object getNextSequenceValue(String schemaName, String > > sequenceName, Connection cx) > > throws SQLException { > > Statement st = cx.createStatement(); > > try { > > ResultSet rs = > > st.executeQuery( "SELECT NEXT VALUE FOR " + sequenceName > > ); > > try { > > if (!rs.next()) { > > throw new SQLException("Could not find next sequence > > value"); > > } > > return rs.getInt(1); > > } finally { > > dataStore.closeSafe(rs); > > } > > } finally { > > dataStore.closeSafe(st); > > } > > } > > > > This is basically the method copied from the oracle-dialect and with the > > sql modified to work with sqlserver. Using getInt instead of getLong is > > asking for trouble, imo, but you probably had your reasons. > > > > yours > > acefael > > > > > > > > > > > > > > _______________________________________________ > > GeoTools-Devel mailing list > > GeoTools-Devel@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/geotools-devel > > > -- > -- > Jody Garnett _______________________________________________ GeoTools-Devel mailing list GeoTools-Devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-devel