Announcement Announcement Module
Collapse
No announcement yet.
Spring Data Neo4j: Default values in NodeBacked entities Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Data Neo4j: Default values in NodeBacked entities

    Hello everyone

    How do you set default values for a field of a newly created NodeBacked entity?
    Setting a default value with initializers or in the constructor marks the corresponding fields as dirty and this initial value is therefore always written to the DB.

    Any best practice how to set default values for fields?


    Best regards,
    James

  • #2
    Good question. Hasn't arisen so far (null was good enough == no property data written in the graph).

    Probably easiest would be a getter that returns the default on null.

    Otherwise I could imagine an annotation attribute would help?

    Michael

    Comment


    • #3
      A getter that returns the default on null is a valid workaround, but does not work with primitive data types.
      An annotation could come to the rescue. Maybe it would be enough to have an attribute "default" in the @GraphProperty annotation?

      PHP Code:
      @NodeEntity
      public class Foo {
        @
      GraphProperty(default=123)
        
      int x;

        @
      GraphProperty(default="foo")
        
      String s;

      Best regards,
      James

      Comment


      • #4
        That's what I thougt too, except for default being a reserved keyword in Java So it will be defaultValue.

        Should be easy enough to get in before the GA.

        Michael

        Comment


        • #5
          That sound great.
          Shell I create a Jira for that?


          Best regards,
          James

          Comment


          • #6
            Yes, please.

            Michael

            Comment


            • #7
              Please see this Jira.

              Regards,
              James

              Comment

              Working...
              X