Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 839113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:24:53+00:00 2026-05-15T05:24:53+00:00

When I use the unit of work pattern (with JPA), I get an entity

  • 0

When I use the unit of work pattern (with JPA), I get an entity from a repository, modify it and save the modifications at the and of the unit of work implicitly to the database.

Now I wonder how to perform validation with the unit of work pattern. If I apply changes (from user input) to a domain object and validate after that, the values of that object would be changed even if validation fails. What is the way to avoid writing an object with illegal state to the database? Roll back the unit of work?

One of the goals of OOP is that objects watch over their own state, so that they never accept illegal values. For this approach I had to throw exceptions and it is the opposite of the bean validation (and spring validation) approach from above. But maybe it is simpler and better.

What validation strategy would you use (in domain driven design)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:24:54+00:00Added an answer on May 15, 2026 at 5:24 am

    What is the way to avoid writing an object with illegal state to the database? Roll back the unit of work?

    If you use the Bean Validation API, it will throw an Exception and changes won’t be persisted (if enabled, validation is supposed to occur at the final stage of the PrePersist, PreUpdate, and PreRemove lifecycle events).

    With JPA 2.0, just put a Bean Validation implementation on the class path.

    With JPA 1.0, refer to this previous answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How we can use Unit of Work pattern with (Entity Framework 4.1) code first
i am using Entity Framework and repository with unit of work design pattern. Sometimes
I use a unit of work pattern a lot in my flex projects. I'll
How should I use the unit of work pattern in the following scenario: I'm
Currently in my application and using the unit of work pattern and generic repository,
I want to build a windosform application using Repository and Unit of Work pattern.
I am trying to use the Unity IoC with the unit of work &
Within our unit tests we use plain ADO.NET (DataTable, DataAdapter) for preparing the database
For a unit test I want to use the Range attribute from NUnit to
I use Microsoft Visual Studio test Tools assembly for unit testing. And from one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.