继续Java,整合Spring Hiberate

我直接把配置文件copy过来的,遇到了2个问题,

1,打开Hibernate.cfg.xml 时,弹出窗口:"this project is not a myeclipse hibernate project . assuming hibernate 3 ...",百度后得到更正的方法:

    使用版本控制的时候,工程根目录下的: .project  和 .myhibernatedata 文件不在版本控制范围内,因此组内成员更新source后,缺少.project 内的ature>com.genuitec.eclipse.hibernate.hibernatenature</nature> 和.myhibernatedata 文件。 

解决:项目名上右键--〉myeclipse-->add hibernate capabilites -->next-->hibernate config file --> existing -->选择现有工程存在的hibernate配置文件--> next --> 不生成factory class --> end

 摘自:http://blog.csdn.net/adolinzi/article/details/5999280

2. 测试spring和Hibernate的整合,报错:

“Unable to get the default Bean Validation”

javax.persistence.validation.mode默认情况下是auto的,就是说如果不设置的话它是会自动去你的classpath下面找一个bean-validation**包,但是找不到,所以beanvalitionFactory错误。 由于javax.persistence.validation.mode的属性值默认是auto,所以会出错。   在hibernate.cfg.xml里将javax.persistence.validation.mode设置为none,就可以避免出错了。     <!-- Disable the BeanValidation -->   <property name="javax.persistence.validation.mode">none</property>

------------------------------------------------------------------------------------------------------------------------------------------

 

 

所以,Hibernate 3.6以上版本在用junit测试时会提示错误:

 

Unable to get the default Bean Validation factory

在hibernate.cfg.xml里增加一属性解决:    

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

第二个错几乎用了2个小时。哎,不熟悉呀。不过还是解决了。

原文地址:https://www.cnblogs.com/zhangxj/p/3940708.html