Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-27-2021 12:26 AM
I am trying to find a way to implement a projection for mapped properties. Following is my code snippets.
Domain Entity
@Data
@Node("DATspace")
public class DatSpace {
@Id @GeneratedValue
private Long neoId;
@Property("SUPtitle")
private String title;
private String SUPid;
}
Test Case
@SpringBootTest
@EnableNeo4jRepositories(basePackages = "com.rahal.marvel")
public class ProjectionTest {
@Autowired
private Neo4jTemplate neo4jTemplate;
interface DATspaceProjection {
String getTitle();
String getSUPid();
}
@Test
public void test_projection(){
DatSpace d = neo4jTemplate.findOne("MATCH (s:DATspace {SUPid: $id}) RETURN s", Collections.singletonMap("id", "SPC_ML7"), DatSpace.class).get();
d.setTitle("title modified");
d.setSUPid("SUPid modified");
DATspaceProjection p = neo4jTemplate.saveAs(d, DATspaceProjection.class);
}
}
Ideally above saveAs function should modify both DATspace.SUPtitle and DATspace.SUPid. However it only modify SUPid but not SUPtitle. I presume it is due to property mapping (@Property) . Is this a bug or are there any workaround?
Solved! Go to Solution.
08-31-2021 01:10 AM
Copied from java - SDN6 - Projection interfaces with Property Mapping - Stack Overflow
The provided @Property
annotation does only have an impact on the annotated property (title
) itself.
There is no knowledge right now that goes from the getTitle()
method in the projection to the annotated title
field in the domain class.
To be safe when modifying this use the explicit property name:
interface DATspaceProjection {
String getSUPtitle();
String getSUPid();
}
I created an issue for improvement Respect `@Property` information in projection. · Issue #2371 · spring-projects/spring-data-neo4j · G...
08-31-2021 01:10 AM
Copied from java - SDN6 - Projection interfaces with Property Mapping - Stack Overflow
The provided @Property
annotation does only have an impact on the annotated property (title
) itself.
There is no knowledge right now that goes from the getTitle()
method in the projection to the annotated title
field in the domain class.
To be safe when modifying this use the explicit property name:
interface DATspaceProjection {
String getSUPtitle();
String getSUPid();
}
I created an issue for improvement Respect `@Property` information in projection. · Issue #2371 · spring-projects/spring-data-neo4j · G...
All the sessions of the conference are now available online