Skip to content

Default values in entities are not used, potentially causes NullPointerExceptions #2565

Closed
@cberes

Description

@cberes

SDN does not respect default values set in entities. This differs from OGM's behavior.

For example, say you have an entity like this

@Getter
@Setter
@Node
public abstract class MyNode {
  @Property("name")
  private String name;

  @Property("active")
  private boolean active = true;

  @Property("age")
  private Integer age = 25;
}

And you create a new node without the active and age properties

CREATE (:MyNode {id: '123', name: 'Nikola Tesla'})

When you query for the node, active will be false and age will be null

MyNode found = myNodeRepository.findById("123").get();
if (!found.isActive()) {                // active is false but it should be true
  found.setAge(found.getAge() - 1);     // age is null: NullPointerException
}

As far as I know, this example has never worked correctly in SDN. Specifically I tried this with 6.3.1 and 6.2.0 and saw the same behavior.

However, this differs from OGM, which uses the default values set in an entity. The tests in this project would pass if run using OGM.

This seems similar to #2348

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions