DATAJDBC-545 - Fix support of setting properties via constructor.
This commit is contained in:
@@ -255,6 +255,17 @@ public class ImmutableAggregateTemplateHsqlIntegrationTests {
|
||||
assertThat(manual.content).isEqualTo("new content");
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-545
|
||||
public void setIdViaConstructor() {
|
||||
|
||||
WithCopyConstructor entity = new WithCopyConstructor(null, "Alfred");
|
||||
|
||||
WithCopyConstructor saved = template.save(entity);
|
||||
|
||||
assertThat(saved).isNotEqualTo(entity);
|
||||
assertThat(saved.id).isNotNull();
|
||||
}
|
||||
|
||||
private static LegoSet createLegoSet(Manual manual) {
|
||||
|
||||
return new LegoSet(null, "Star Destroyer", manual, null);
|
||||
@@ -296,6 +307,17 @@ public class ImmutableAggregateTemplateHsqlIntegrationTests {
|
||||
String name;
|
||||
}
|
||||
|
||||
static class WithCopyConstructor {
|
||||
@Id
|
||||
private final Long id;
|
||||
private final String name;
|
||||
|
||||
WithCopyConstructor(Long id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Import(TestConfiguration.class)
|
||||
static class Config {
|
||||
|
||||
@@ -23,3 +23,9 @@ CREATE TABLE AUTHOR
|
||||
ALTER TABLE AUTHOR
|
||||
ADD FOREIGN KEY (LEGO_SET)
|
||||
REFERENCES LEGO_SET (id);
|
||||
|
||||
CREATE TABLE WITH_COPY_CONSTRUCTOR
|
||||
(
|
||||
ID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY,
|
||||
NAME VARCHAR(30)
|
||||
);
|
||||
|
||||
@@ -105,13 +105,4 @@ class RelationalPersistentEntityImpl<T> extends BasicPersistentEntity<T, Relatio
|
||||
public String toString() {
|
||||
return String.format("JdbcPersistentEntityImpl<%s>", getType());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mapping.model.BasicPersistentEntity#setPersistentPropertyAccessorFactory(org.springframework.data.mapping.model.PersistentPropertyAccessorFactory)
|
||||
*/
|
||||
@Override
|
||||
public void setPersistentPropertyAccessorFactory(PersistentPropertyAccessorFactory factory) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user