2 sinat 25596967 sinat_25596967 于 2015.06.02 20:22 提问

小白求教,第一次搭建失败hibernate

图片说明

用的是myeclipse自带的hibernate

这是错误信息

信息: Hibernate Validator bean-validator-3.0-JBoss-4.0.2
Exception in thread "main" org.hibernate.HibernateException: Error applying BeanValidation relational constraints
at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.applyRelationalConstraints(BeanValidationIntegrator.java:219)
at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:126)
at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:306)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1744)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1782)
at hibernate_test.NewsManger.main(NewsManger.java:14)
Caused by: java.lang.reflect.InvocationTargetException
at 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.BeanValidationIntegrator.applyRelationalConstraints(BeanValidationIntegrator.java:208)
... 5 more
Caused by: org.hibernate.HibernateException: Unable to build the default ValidatorFactory
at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:524)
at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:119)
... 10 more
Caused by: javax.validation.ValidationException: Unable to instantiate Configuration.
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:272)
at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111)
at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:521)
... 11 more
Caused by: java.lang.NullPointerException
at 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.(ResourceBundleMessageInterpolator.java:81)
at org.hibernate.validator.engine.ResourceBundleMessageInterpolator.(ResourceBundleMessageInterpolator.java:73)
at org.hibernate.validator.engine.ConfigurationImpl.(ConfigurationImpl.java:57)
at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:43)
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:269)
... 13 more

3个回答

sushengmiyan
sushengmiyan   Rxr 2015.06.03 09:44
    //1. 创建一个 SessionFactory 对象
    SessionFactory sessionFactory = null;

    //1). 创建 Configuration 对象: 对应 hibernate 的基本配置信息和 对象关系映射信息
    Configuration configuration = new Configuration().configure();

    //2). 创建一个 ServiceRegistry 对象: hibernate 4.x 新添加的对象
    //hibernate 的任何配置和服务都需要在该对象中注册后才能有效.
    ServiceRegistry serviceRegistry = 
            new ServiceRegistryBuilder().applySettings(configuration.getProperties())
                                        .buildServiceRegistry();

    //3).
    sessionFactory = configuration.buildSessionFactory(serviceRegistry);

    //2. 创建一个 Session 对象
    Session session = sessionFactory.openSession();

    //3. 开启事务
    Transaction transaction = session.beginTransaction();

    session.save(this.orm);

    //5. 提交事务 
    transaction.commit();

    //6. 关闭 Session
    session.close();

    //7. 关闭 SessionFactory 对象
    sessionFactory.close(); 

    你试试这样子
weixin_28690107
weixin_28690107 谢谢啊
大约 3 年之前 回复
devmiao
devmiao   Ds   Rxr 2015.06.02 20:32

你的试题类的验证有问题,看看输入是什么

sinat_25596967
sinat_25596967 可以说具体一点吗?不太懂。很感谢你的回答。
大约 3 年之前 回复
qsef2015
qsef2015   2015.06.02 20:34

javax.validation.ValidationException: Unable to instantiate Configuration.
你这个是压根就没指定configure文件吧,hibernate连数据源都不知道.

sinat_25596967
sinat_25596967 我是hibernate.cfg.xml配置文件的,但问题问题就在这里。感谢你的回答
大约 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!