Announcement Announcement Module
No announcement yet.
Validation on TYPE, METHOD not just FIELD Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Validation on TYPE, METHOD not just FIELD

    (rephrasing a question about validation which really had to do with uniqueness)....

    Spring Neo4j does exactly what I need when storing beans with complex child properties (i.e. that are themselves either beans or collections of beans) automatically as nodes with a relation to the parent bean (which is recursively done down the property hierarchy). So basically with the help of the @Fetch annotation (with care not to have recursive associations) I can roll "complex" beans back and forth into Neo4j without doing much that isn't out of the box.

    Thing is when I persist a bean I originally thought about using Validation to enforce the complex child properties had a graph id and were not transient. For example, if I had a Post bean (representing a forum post) and added Tag beans into a collection property then I wanted to make sure that each Tag had a non-null graph id "ensuring" that the uniqueness of Tags was checked previously prior to being @RelatedTo automatically by Spring Neo4j. Validation per Spring Neo4j apparently only works on fields (not constraints on TYPE which is where I needed a custom constraint to pull out type information). Good since it made me think twice.

    What I really want to do is catch the action in Spring Neo4j (or the underlying Spring data) that persists an entity and check for uniqueness. But in my way. Which isn't based off only the key/value pairs in the entity but also inside the key/value pairs of nested properties (i.e. running a Cypher query with where conditions on the entity and related entities). Little along the lines of what Tobias is saying:

    To do this I need 2 things: 1) a way to jack into Spring Neo4j persistence like a before advice and 2) access to the entire bean being persisted not just the simple properties of the node (after all Neo4j saves nodes as a bunch of primitive properties). The UniqueFactory works at the database level (?) whereas I need to react that the domain model level (Spring Neo4j/Data).
    Last edited by young_matthewd; Feb 28th, 2012, 03:04 PM. Reason: Rethought

  • #2
    Right now there are no official place to hook in.

    If I understand you correctly you want to be called back for every entity in the tree before it is persisted?

    It might be possible to subclass a bunch of classes and override the behavior but I think that is not what's intended.

    So perhaps you could specify you needs and an API for the callback in a JIRA issue?

    Thanks a lot



    • #3
      Exactly, I want to capture the call for every entity prior to it being persisted and hopefully be able to see the entire bean (not just the subset of primitive properties to be persisted).

      No hooks now. What about AOP on the right Spring-Data or Spring-Neo4j (or Neo4j) method?

      Will step through the call and write something up.

      Not sure if what I want to do is all that "general". I am marking beans for unique based on the entire bean structure not the Neo4j representation. My basis for unique is a set of criteria on properties (nested or not). More like a composite unique index defined by the application.