Results 1 to 7 of 7

Thread: Spring Data Neo4j: Default values in NodeBacked entities

  1. #1
    Join Date
    Oct 2006
    Location
    Zürich
    Posts
    101

    Default 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. #2
    Join Date
    Jan 2011
    Location
    Dresden, Germany
    Posts
    525

    Default

    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

  3. #3
    Join Date
    Oct 2006
    Location
    Zürich
    Posts
    101

    Default

    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

  4. #4
    Join Date
    Jan 2011
    Location
    Dresden, Germany
    Posts
    525

    Default

    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

  5. #5
    Join Date
    Oct 2006
    Location
    Zürich
    Posts
    101

    Default

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


    Best regards,
    James

  6. #6
    Join Date
    Jan 2011
    Location
    Dresden, Germany
    Posts
    525

    Default

    Yes, please.

    Michael

  7. #7
    Join Date
    Oct 2006
    Location
    Zürich
    Posts
    101

    Default

    Please see this Jira.

    Regards,
    James

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •