Skip to content

Commit 76906b8

Browse files
committed
DATAJDBC-545 - Fix support of setting properties via constructor.
1 parent 496d953 commit 76906b8

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/ImmutableAggregateTemplateHsqlIntegrationTests.java

+22
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,17 @@ public void changeReferencedEntity() {
255255
assertThat(manual.content).isEqualTo("new content");
256256
}
257257

258+
@Test // DATAJDBC-545
259+
public void setIdViaConstructor() {
260+
261+
WithCopyConstructor entity = new WithCopyConstructor(null, "Alfred");
262+
263+
WithCopyConstructor saved = template.save(entity);
264+
265+
assertThat(saved).isNotEqualTo(entity);
266+
assertThat(saved.id).isNotNull();
267+
}
268+
258269
private static LegoSet createLegoSet(Manual manual) {
259270

260271
return new LegoSet(null, "Star Destroyer", manual, null);
@@ -296,6 +307,17 @@ static class Author {
296307
String name;
297308
}
298309

310+
static class WithCopyConstructor {
311+
@Id
312+
private final Long id;
313+
private final String name;
314+
315+
WithCopyConstructor(Long id, String name) {
316+
this.id = id;
317+
this.name = name;
318+
}
319+
}
320+
299321
@Configuration
300322
@Import(TestConfiguration.class)
301323
static class Config {

spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.core/ImmutableAggregateTemplateHsqlIntegrationTests-hsql.sql

+6
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ CREATE TABLE AUTHOR
2323
ALTER TABLE AUTHOR
2424
ADD FOREIGN KEY (LEGO_SET)
2525
REFERENCES LEGO_SET (id);
26+
27+
CREATE TABLE WITH_COPY_CONSTRUCTOR
28+
(
29+
ID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY,
30+
NAME VARCHAR(30)
31+
);

spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalPersistentEntityImpl.java

-9
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,4 @@ public SqlIdentifier getIdColumn() {
105105
public String toString() {
106106
return String.format("JdbcPersistentEntityImpl<%s>", getType());
107107
}
108-
109-
/*
110-
* (non-Javadoc)
111-
* @see org.springframework.data.mapping.model.BasicPersistentEntity#setPersistentPropertyAccessorFactory(org.springframework.data.mapping.model.PersistentPropertyAccessorFactory)
112-
*/
113-
@Override
114-
public void setPersistentPropertyAccessorFactory(PersistentPropertyAccessorFactory factory) {
115-
116-
}
117108
}

0 commit comments

Comments
 (0)