Search code examples
neo4jspring-data-neo4j-4neo4j-ogm

Neo4j ignores Enums


Working with Neo4j I created a TSUser object that has a state showing if the user is active or not. When i create the user in the Neo4j DB, the state is not shown, as if it was transient. However, when i load the user in the code (while debugging), the enum-attribute is set. I would like to see it in the Neo4j client.

The TSUser looks like this:

@NodeEntity
public class TSUser{

  private Long id;
  private State state;
  private String username;
  private String email;

  //Getter/Setter

}

with State being

public enum State{
  ACTIVE, INACTIVE
}

After persisting an TSUser, i fetch him in the client with "MATCH n RETURN n" and get the result as shown on the picture. User without state


Solution

  • The enum State has to be belong to the list of packages supplied to the SessionFactory. If not, it will not be persisted.

    You're probably seeing this value in debug mode because you're in the same session, and reloading the entity loads and maps username and email, but leaves state alone since it does not exist in the graph. If you were to do a session.clear() before loading the entity, you would find the value missing.