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 8868381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:15:37+00:00 2026-06-14T17:15:37+00:00

Validation using hibernate validator fails on the fields marked as @Transient and @NotNull .

  • 0

Validation using hibernate validator fails on the fields marked as @Transient and @NotNull.
However it fails only for those that were already stored in the DB, but now are traversed in the tree of objects. (as their value is null of course)

For the entities like this:

public class User {

  @ManyToMany
  @Fetch(org.hibernate.annotations.FetchMode.JOIN)
  @Valid
  private Set<Role> roles;

  @NotNull
  private String someField;
}

public class Role {

  @ManyToMany
  @Fetch(org.hibernate.annotations.FetchMode.JOIN)
  @Valid
  private Set<User> users;
}

As I do the validation of the User and there are more users with particular Role I have problem, that even if the current user validation succeeds, for the others I’m getting error.

I do this validation on the client side prio to submitting data to server side.

I’ve seen some ideas how to fix problems with validation of @Transient and @NotNull:

  • ConstraintViolationException: User Entity with transient confirmPassword field

  • Ignore transient pattern on save hibernate entity

However these didn’t cover my case (of having violations on related objects). And moreover I didn’t come to validation problems on server side yet :). As to test that would be a next step.

So the question is, is there any way to explain validator, that transitive objects fetched from DB should be skipped during validation?

I was thinking of extending the JPATraversableResolver that I currently use by overriding:

 /**
     * Determine if the Bean Validation provider is allowed to reach the property state
     *
     * @param traversableObject object hosting <code>traversableProperty</code> or null  
     *                          if validateValue is called
     * @param traversableProperty the traversable property.
     * @param rootBeanType type of the root object passed to the Validator.
     * @param pathToTraversableObject path from the root object to
     *        <code>traversableObject</code>
     *        (using the path specification defined by Bean Validator).
     * @param elementType either <code>FIELD</code> or <code>METHOD</code>.
     *
     * @return <code>true</code> if the Bean Validation provider is allowed to
     *         reach the property state, <code>false</code> otherwise.
     */
     boolean isReachable(Object traversableObject,
                     Path.Node traversableProperty,
                     Class<?> rootBeanType,
                     Path pathToTraversableObject,
                     ElementType elementType);

however, I still face the problem of determining which properties to check and which not.
If my check would be for transient fields of the currently persisted object, I’d not cover the case of persisting entities (2 related ones), where check would be on one of them and the other one would have problematic transient field.

Any ideas? Any experiences with that?

  • 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-06-14T17:15:38+00:00Added an answer on June 14, 2026 at 5:15 pm

    OK, as no suggestion came, let me answer myself 🙂

    I ended up with having special validation group on transient fields, and for this group I implemented separate TraversableResolver that just checks, am I still directly in the validated entity?

    This is done via check in: TraversableResolver.isReachable where pathToTraversableObject is checked for empty Strnig.

    The reason for solution is that I was not able to validate related entities, as I was not able to decide if these need a validation or not (if they were modified or not). But the one that I’m submitting needs a validation for sure.

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

Sidebar

Related Questions

I am using spring 3.1 with hibernate validator 4.2. I observe that hibernate validation
I'm trying to integrate bean validation using hibernate validator to my web application :
I'm using spring based validation in combination with hibernate validator enabled by the following
I create form and controller this form have some validation constrains using Hibernate validator.
I am using Hibernate validator for form validation in my web-app. I am using
I'm using Hibernate validator 4.1 to validate my Entity. I have a dashboard that
I am using hibernate validator to validate a form. However the validator does not
First, let me explain that I'm using Spring MVC 3.1.1, and Hibernate validation 4.2.0.
I'm using Hibernate Validator 4.0.2, Spring 3.0 and Hibernate 3.3.2 (which, as I understand
I'm working on a Spring MVC project in which I'm using Hibernate Validator to

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.