1515 */
1616package org .springframework .data .jdbc .core ;
1717
18+ import static java .util .Collections .*;
1819import static org .assertj .core .api .Assertions .*;
1920
2021import java .util .Map ;
2627import org .springframework .data .annotation .Id ;
2728import org .springframework .data .jdbc .core .mapping .PersistentPropertyPathTestUtils ;
2829import org .springframework .data .mapping .PersistentPropertyPath ;
29- import org .springframework .data .mapping .PropertyPath ;
30+ import org .springframework .data .relational . core . mapping .NamingStrategy ;
3031import org .springframework .data .relational .core .mapping .RelationalMappingContext ;
3132import org .springframework .data .relational .core .mapping .RelationalPersistentEntity ;
3233import org .springframework .data .relational .core .mapping .RelationalPersistentProperty ;
33- import org .springframework .data .relational .core .mapping .NamingStrategy ;
3434
3535/**
3636 * Unit tests for the {@link SqlGenerator}.
@@ -46,10 +46,16 @@ public class SqlGeneratorUnitTests {
4646@ Before
4747public void setUp () {
4848
49+ this .sqlGenerator = createSqlGenerator (DummyEntity .class );
50+ }
51+
52+ SqlGenerator createSqlGenerator (Class <?> type ) {
53+
4954NamingStrategy namingStrategy = new PrefixingNamingStrategy ();
5055RelationalMappingContext context = new RelationalMappingContext (namingStrategy );
51- RelationalPersistentEntity <?> persistentEntity = context .getRequiredPersistentEntity (DummyEntity .class );
52- this .sqlGenerator = new SqlGenerator (context , persistentEntity , new SqlGeneratorSource (context ));
56+ RelationalPersistentEntity <?> persistentEntity = context .getRequiredPersistentEntity (type );
57+
58+ return new SqlGenerator (context , persistentEntity , new SqlGeneratorSource (context ));
5359}
5460
5561@ Test // DATAJDBC-112
@@ -170,10 +176,20 @@ public void findAllByPropertyWithKeyOrdered() {
170176+ "WHERE back-ref = :back-ref " + "ORDER BY key-column" );
171177}
172178
179+ @ Test // DATAJDBC-264
180+ public void getInsertForEmptyColumnList () {
181+
182+ SqlGenerator sqlGenerator = createSqlGenerator (IdOnlyEntity .class );
183+
184+ String insert = sqlGenerator .getInsert (emptySet ());
185+
186+ assertThat (insert ).endsWith ("()" );
187+ }
173188
174189private PersistentPropertyPath <RelationalPersistentProperty > getPath (String path , Class <?> base ) {
175190return PersistentPropertyPathTestUtils .getPath (context , path , base );
176191}
192+
177193@ SuppressWarnings ("unused" )
178194static class DummyEntity {
179195
@@ -212,4 +228,11 @@ public String getColumnName(RelationalPersistentProperty property) {
212228}
213229
214230}
231+
232+ @ SuppressWarnings ("unused" )
233+ static class IdOnlyEntity {
234+
235+ @ Id Long id ;
236+ }
237+
215238}
0 commit comments