hibernate在web下一个错误
今天第一次在web下运行,不给力啊,出现了下面的错误。
Hibernate Validator bean-validator-3.0-JBoss-4.0.2
Exception in thread "main" org.hibernate.HibernateException: Unable to get the default Bean Validation factory
at org.hibernate.cfg.beanvalidation.BeanValidationActivator.applyDDL(BeanValidationActivator.java:127)
at org.hibernate.cfg.Configuration.applyBeanValidationConstraintsOnDDL(Configuration.java:1674)
at org.hibernate.cfg.Configuration.applyConstraintsToDDL(Configuration.java:1624)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1415)
at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:972)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:130)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:92)
at com.zhang.bean.TestHibernate.testExport(TestHibernate.java:39)
at com.zhang.bean.TestHibernate.main(TestHibernate.java:19)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.cfg.beanvalidation.BeanValidationActivator.applyDDL(BeanValidationActivator.java:118)
... 8 more
Caused by: org.hibernate.HibernateException: Unable to build the default ValidatorFactory
at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:345)
at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:106)
... 13 more
查了半天的,找到改正的方法,需要在hibernate.cfg.xml中配置<property?name="javax.persistence.validation.mode">none</property>??
具体原因
- 23.1.1.?Adding?Bean?Validation??
- ??
- To?enable?Hibernate's?Bean?Validation?integration,?simply?add?a?Bean?Validation?provider?(preferably?Hibernate?Validation?4)?on?your?classpath.??
- ??
- 23.1.2.?Configuration??
- ??
- By?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?Hibernate??
- callback:?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.??
- 注意??
- 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?except?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?(,) ?