Spring Data Neo4j SDN 6 @CreatedDate not working

(or maybe I don't know how to make it work)

I have @EnableNeo4jAuditing on the @Configuration class and @LastModifiedDate works just fine!

But how do I get the created date set? It stays null, no matter which data type I use. What am I missing? (Spring Boot 2.4.0, Java 15)

THANKS for any help or hints!

Cheers, Chris

I assume that you are using assigned identifiers(?). In this case SDN cannot distinguish between new or existing entity because the identifier controls the isNew detection.

Hi Gerrit,

Here is the simple example I am playing around with:

@Node
public class Movie {

	@Id @GeneratedValue private long id;
	@Version private Long version;
	@CreatedDate private LocalDateTime created;
	@LastModifiedDate private LocalDateTime modified;

	private String title;
	private String tagline;
	private Integer released;
...

modified is set correctly on each change, created is never set.

What has to be done to make this work?

In the past I had an OGM EventListenerAdapter that would set created and modified for me but I thought I would give this built in feature a try. Oh BTW is there a doc/example somewhere how to implement something like an "onPreSave" in the new SDN 6?

Cheers,
Chris

Any info is appreciated ;)

Short answer: Use a Long instead of the primitive long as the type for you id.

Longer answer: Due to the fact that Neo4j now handles also 0 as a valid identifier value, SDN cannot determine if the node is new or not. As a result it returns false for the new check because the primitive long is 0.

Oh - LOL! ... and I was playing with different types of the created field
Thanks!