当前位置: 代码迷 >> Web前端 >> hibernate在web上一个异常
  详细解决方案

hibernate在web上一个异常

热度:556   发布时间:2012-12-21 12:03:49.0
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>??

具体原因

  1. 23.1.1.?Adding?Bean?Validation??
  2. ??
  3. To?enable?Hibernate's?Bean?Validation?integration,?simply?add?a?Bean?Validation?provider?(preferably?Hibernate?Validation?4)?on?your?classpath.??
  4. ??
  5. 23.1.2.?Configuration??
  6. ??
  7. By?default,?no?configuration?is?necessary.??
  8. ??
  9. The?Default?group?is?validated?on?entity?insert?and?update?and?the?database?model?is?updated?accordingly?based?on?the?Default?group?as?well.??
  10. ??
  11. 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:??
  12. ??
  13. auto?(default):?enable?integration?between?Bean?Validation?and?Hibernate?(callback?and?ddl?generation)?only?if?Bean?Validation?is?present?in?the?classpath.??
  14. none:?disable?all?integration?between?Bean?Validation?and?Hibernate??
  15. 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.??
  16. 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.??
  17. 注意??
  18. You?can?use?both?callback?and?ddl?together?by?setting?the?property?to?callback,?dll??
  19. ??
  20. <persistence?...>??
  21. ??<persistence-unit?...>??
  22. ????...??
  23. ????<properties>??
  24. ??????<property?name="javax.persistence.validation.mode"??
  25. ????????????????value="callback,?ddl"/>??
  26. ????</properties>??
  27. ??</persistence-unit>??
  28. </persistence>??
  29. This?is?equivalent?to?auto?except?that?if?no?Bean?Validation?provider?is?present,?an?exception?is?raised.??
  30. If?you?want?to?validate?different?groups?during?insertion,?update?and?deletion,?use:??
  31. ??
  32. javax.persistence.validation.group.pre-persist:?groups?validated?when?an?entity?is?about?to?be?persisted?(default?to?Default)??
  33. javax.persistence.validation.group.pre-update:?groups?validated?when?an?entity?is?about?to?be?updated?(default?to?Default)??
  34. javax.persistence.validation.group.pre-remove:?groups?validated?when?an?entity?is?about?to?be?deleted?(default?to?no?group)??
  35. org.hibernate.validator.group.ddl:?groups?considered?when?applying?constraints?on?the?database?schema?(default?to?Default)??
  36. Each?property?accepts?the?fully?qualified?class?names?of?the?groups?validated?separated?by?a?comma?(,) ?

  相关解决方案