Hibernate error: org. hibernate. hibernateexception: unable to get the default bean validation Factory

Source: Internet
Author: User

I took a look at the tutorial a few days ago and tried to configure hibernate on the Web. when there was a tragedy, the following error message was prompted:

Information: hibernate validator bean-validator-3.0-JBoss-4.0.2Exception in thread "Main" org. hibernate. hibernateexception: unable to get the default bean validation factoryat Org. hibernate. cfg. beanvalidation. beanvalidationactivator. applyddl (beanvalidationactivator. java: 127) at Org. hibernate. cfg. configuration. applybeanvalidationconstraintsonddl (configuration. java: 1704) at Org. hibernate. cfg. configuration. applyconstraintstoddl (configuration. java: 1654) at Org. hibernate. cfg. configuration. secondpasscompile (configuration. java: 1445) at Org. hibernate. cfg. configuration. buildsessionfactory (configuration. java: 1856) at HB. sh. model. mainclass. main (mainclass. java: 9) caused by: Java. lang. reflect. invocationtargetexceptionat sun. reflect. nativemethodaccessorimpl. invoke0 (native method) at Sun. reflect. nativemethodaccessorimpl. invoke (nativemethodaccessorimpl. java: 39) at Sun. reflect. delegatingmethodaccessorimpl. invoke (delegatingmethodaccessorimpl. java: 25) at java. lang. reflect. method. invoke (method. java: 597) at Org. hibernate. cfg. beanvalidation. beanvalidationactivator. applyddl (beanvalidationactivator. java: 118 )... 5 morecaused by: Org. hibernate. hibernateexception: unable to build the default validatorfactoryat Org. hibernate. cfg. beanvalidation. typesafeactivator. getvalidatorfactory (typesafeactivator. java: 383) at Org. hibernate. cfg. beanvalidation. typesafeactivator. applyddl (typesafeactivator. java: 109 )... 10 morecaused by: javax. validation. validationexception: Unable to instantiate configuration. at javax. validation. validation $ genericbootstrapimpl. configure (validation. java: 272) at javax. validation. validation. builddefavalivalidatorfactory (validation. java: 111) at Org. hibernate. cfg. beanvalidation. typesafeactivator. getvalidatorfactory (typesafeactivator. java: 380 )... 11 morecaused by: Java. lang. nullpointerexceptionat Java. util. resourcebundle. getbundle (resourcebundle. java: 960) at Org. hibernate. validator. engine. resourcebundlemessageinterpolator. loadbundle (resourcebundlemessageinterpolator. java: 202) at Org. hibernate. validator. engine. resourcebundlemessageinterpolator. getfilebasedresourcebundle (resourcebundlemessageinterpolator. java: 182) at Org. hibernate. validator. engine. resourcebundlemessageinterpolator. <init> (resourcebundlemessageinterpolator. java: 81) at Org. hibernate. validator. engine. resourcebundlemessageinterpolator. <init> (resourcebundlemessageinterpolator. java: 73) at Org. hibernate. validator. engine. configurationimpl. <init> (configurationimpl. java: 57) at Org. hibernate. validator. hibernatevalidator. creategenericconfiguration (hibernatevalidator. java: 43) at javax. validation. validation $ genericbootstrapimpl. configure (validation. java: 269 )... 13 more

After several days of traveling on the internet, I did not find a solution. However, I had no choice but to try my best. I tried to read the hibernate help documentation, search for validation, open the youdao dictionary, translate and read the help documentation, I hope it can help me, but I am not willing to help myself. I finally found a paragraph:

23.1.1. adding bean validationto enable hibernate's bean validation integration, simply add a bean validation provider (preferably hibernate validation 4) on your classpath.23.1.2. configurationby default, no configuration is necessary. the default group is validated on entity insert and update and the database model is updated accordingly based on the default group as well. you can customize the bean validation integration by setting the validation mode. use the javax. persistence. validation. mode property and set it up for example in your persistence. XML file or your hibernate. cfg. XML file. several options are possible: auto (default): Enable integration between bean validation and hibernate (callback and DDL generation) only if bean validation is present in the classpath. none: Disable all integration between bean validation and hibernatecallback: only validate entities when they are either inserted, updated or deleted. an exception is raised if no bean validation provider is present in the classpath. DDL: only apply constraints to the database schema when generated by hibernate. an exception is raised if no bean validation provider is present in the classpath. this value is not defined by the Java persistence spec and is specific to hibernate. note that you can use both callback and DDL together by setting the property to callback, DLL <persistence...> <persistence-unit...>... <Properties> <property name = "javax. persistence. validation. mode "value =" Callback, DDL "/> </Properties> </persistence-unit> </persistence> This is equivalent to auto Scaling T that if no bean validation provider is present, an exception is raised. if you want to validate different groups during insertion, update and deletion, use: javax. persistence. validation. group. pre-persist: groups validated when an entity is about to be persisted (default to default) javax. persistence. validation. group. pre-Update: groups validated when an entity is about to be updated (default to default) javax. persistence. validation. group. pre-Remove: groups validated when an entity is about to be deleted (default to no group) Org. hibernate. validator. group. DDL: groups considered when applying constraints on the database schema (default to default) each property accepts the fully qualified class names of the groups validated separated by a comma (,)

In hibernate. cfg. xml orThe persistence. xml file needs to be configuredJavax. Persistence. validation. mode attribute

I don't know what it means, so I directly added the attributes to my hibernate. cfg. xml file:

<property name="javax.persistence.validation.mode">none</property>

Sorry, I don't even report an error in hibernate. Excited,Javax. persistence. validation. mode is auto by default, that is, if it is not set, it will automatically go to your classpath to find a bean-validation ** package, but it cannot be found, so the beanvalitionfactory error.

Well, today we can finally make it easy &......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.