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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:23:25+00:00 2026-05-26T07:23:25+00:00

I’m looking to see whether or not the following is even possible, as all

  • 0

I’m looking to see whether or not the following is even possible, as all preliminary searches haven’t turned back anything to indicate either way.

I’d like to use Hibernate’s Validator annotations to validate bean methods, and I would like to use some AOP framework (Spring, AOP Alliance, AspectJ, etc.) to intercept methods annotated with a subset of the Hibernate Validator annotations (@NotNull, @NotEmpty, @Email, etc.); I then want AOP advice to run when they are encountered.

Is this possible to do? If so, I am having a tough time visualizing how the code would work. Using Spring AOP’s MethodInterceptor interface as an example:

First, the bean using Hibernate Validator:

public class SomeBean
{
    private String data;

    // Hibernate Validator annotation specifying that "data" cannot be an empty
    // string.
    @NotEmpty
    public String getData() { ... } // etc.
}

Then, some code using that bean:

public void someMethod()
{
    SomeBean oBean = new SomeBean();

    // Validation should fail because we specified that "data" cannot be empty.
    oBean.setData("");
}

Next, the AOP advice to be ran when Hibernate Validator-annotated methods are encountered.

public class ValidationInterceptor implements MethodInterceptor
{
    public Object invoke(MethodInvocation invocation)
    {
        // Here's where we would use Hibernate's validator classes.
        // My code example here is wrong, but it gets the point across.
        Class targetClass = invocation.getClass(); // Should give me SomeBean.class
        ClassValidator<targetClass> oValidator= new ClassValidator<targetClass>();

        // Here I need to get a reference to the instance of the offending
        // SomeBean object whose data has been set to empty...not sure how!
        SomeBean oOffendingBean = getTheBadBeanSomehow();

        InvalidValue[] badVals = oValidator.getInvalidValues(oOffendingBean);
    }
}

So, not only am I choking on what the Spring AOP (pointcut definitions, etc.) configuration would look like to intercept the Hibernate Validator annotations I want, and not only do I not fully grasp how to implement the actual advice (e.g. how to instantiate the offending SomeBean from inside the advice as I mention above in the comments), but I’m not even sure if this solution is possible, Spring or otherwise.

Thanks in advance for some gentle “nudges” in the right direction!

  • 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-26T07:23:26+00:00Added an answer on May 26, 2026 at 7:23 am

    You might be interested in the method validation feature introduced with Hibernate Validator 4.2 which provides support for validating method parameters and return values.

    You then might use Seam Validation which integrates this functionality with CDI. If you want to use method validation together with Spring you could have a look this project on GitHub which shows how to integrate the method validation functionality with Spring AOP (disclaimer: I’m the author of this project as well as of Seam Validation).

    To make your example working you would have to annote the parameter of the setter method with @NotEmpty like this:

    public class SomeBean {
    
        private String data;
    
        @NotEmpty
        public String getData() { return data; }
    
        public void setData(@NotEmpty String data) { this.data = data; }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.