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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:35:45+00:00 2026-05-25T03:35:45+00:00

I am trying to add a unit test for an annotated bean in spring

  • 0

I am trying to add a unit test for an annotated bean in spring using JSR-303 validation.

The bean is a simple one like this:

public class Bean {
   @Size(max=XX)  
   String text;  
}  

In the Spring config I have the all the necessary JAR-files:

 validation-api  
 hibernate-validator

The validator is initialized with:

<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />

My attempt at a testcase looks like this (the spring and other fluff removed):

@Autowired
private LocalValidatorFactoryBean factory;


@Test
public void testTemplateFormBeanValidation() {
// TODO exception at the moment. Can not resolve the validator. Provider issue.
factory.setProviderClass(HibernateValidator.class);
factory.setTraversableResolver(new DefaultTraversableResolver());
Validator val = factory.getValidator();
TemplateFormBean fb1 = new TemplateFormBean();
fb1.setText("this text works");
Set<ConstraintViolation<TemplateFormBean>> constraints = val.validate(fb1);
assertNull(constraints);

}

When I run this test I get the following stacktrace:

java.lang.AbstractMethodError: javax/persistence/spi/PersistenceProvider.getProviderUtil()Ljavax/persistence/spi/ProviderUtil;
at javax.persistence.Persistence$1.isLoaded(Persistence.java:78)
at org.hibernate.validator.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:62)
at org.hibernate.validator.engine.resolver.DefaultTraversableResolver.isReachable(DefaultTraversableResolver.java:94)
at org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver.isReachable(SingleThreadCachedTraversableResolver.java:47)
at org.hibernate.validator.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:757)
at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:324)
at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForRedefinedDefaultGroup(ValidatorImpl.java:273)
at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:256)
at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:210)
at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:119)
at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:145)
at general.TestValidationBeans.testTemplateFormBeanValidation(TestValidationBeans.java:30)

Am I missing some dependencies? I am using Hibernate with JPA2 annotations as persistence, so all those JARs exist and are working.

The version of Hibernate is:

2011-04-19 08:37:47 [INFO] Version - Hibernate Commons Annotations 3.2.0.Final
2011-04-19 08:37:47 [INFO] Environment - Hibernate 3.6.2.Final
2011-04-19 08:37:47 [INFO] Environment - hibernate.properties not found
2011-04-19 08:37:47 [INFO] Environment - Bytecode provider name : javassist
...
2011-04-19 08:37:47 [INFO] Version - Hibernate Validator 4.1.0.Final

Why isn´t Hibernate logging the version of hibernate-annotations? According to docs it is bundled from hibernate 3.5 in hibernate3.jar which I am using.
Should I see log output for hibernate annotations (something like “Version – Hibernate Annotations 3.4.0 GA)?

  • 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-25T03:35:45+00:00Added an answer on May 25, 2026 at 3:35 am

    I have a simpler set-up using context configuration as follows:

    MyTest.java

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration
    public class MyTest {
    
        @Autowired
        private Validator validator;
    
    
        @Test
        public void testMyForm() {
            final MyForm form = new MyForm();
            .
            .
            final Set<ConstraintViolation<MyForm>> violations = validator.validate(form);
            assertTrue(violations.isEmpty());
        }
    }
    

    MyTest-context.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd">
    
        <bean id="validator"
            class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
    
    </beans>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to set up JSR-303 validation of forms using Spring MVC. I had
I'm trying add a tab to my web page that looks like this: Using
I'm trying to unit test some code that looks like this: def main(): parser
I am trying to add my first unit test to an existing Open Source
I'm trying to unit test a custom WPF control using NUnit. The control is
I am trying to write my first unit test for one of my service
I am trying to use Boost Test to add some much needed unit tests
I am trying to build a very simple C++ unit test project. The setup
Recently I was trying to add unit tests to an existing binary by creating
I'm trying to write a unit test for a class that generates distinct strings.

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.