Results 1 to 3 of 3

Thread: Entity constraints validation using SpringData mongo repository

  1. #1
    Join Date
    Mar 2012
    Posts
    4

    Default Entity constraints validation using SpringData mongo repository

    Hi,

    I am using SpringData for mongoDb and have defined marker repository interfaces for my entities. All repositories extend a custom parent repository. I need to perform validation on my entities before saving them.

    Since repository implementations are proxied at runtime I don't have a handle to write validate method in each repository. How do I ensure validation is invoked on each entity prior to save?

    I have other requirements too where few child repositories may choose to override behavior of some methods.

    - Auto generating GUID for all entities that are being saved. Logic to generate the id resides with the repository.



    Thanks,
    Sid
    Last edited by ssharma; Mar 26th, 2012 at 08:01 AM. Reason: More info

  2. #2
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    492

    Default

    As the repository infrastructure uses MongoTemplate have a look at the events [0] we support and implement a custom event listener.

    [0] http://static.springsource.org/sprin...e-summary.html

  3. #3
    Join Date
    Mar 2012
    Posts
    4

    Default

    Thanks Oliver. I will flirt with BeforeSaveEvent<E>.

    -Sid

Tags for this Thread

Posting Permissions

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