org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file
[/home/allenlogo/Workspaces/MyEclipse 10/Test26/src/applicationContext.xml]: Invocation of init method failed;
nested exception is org.hibernate.HibernateException: Error applying BeanValidation relational constraints
以上是错误信息,解决办法是:在hibernate.cfg.xml文件里加上
<property name="javax.persistence.validation.mode">none</property>
具体原因详见新浪博客:点击打开链接感谢原作者分享。
还有一个小问题:Spring3.1和Hibernate4之间,
ApplicationContext context = new FileSystemXmlApplicationContext("src/applicationContext.xml");
HibernateTemplate hib = (HibernateTemplate) context.getBean("hinernate_test");
Tuser tu = (Tuser) hib.load(Tuser.class, "lpf");
System.out.println( tu.getUserName() );
这样使用代码会出现如下错误:
Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;
原因应该是:spring3.1.1还没有整合hibernate4.0,还是用的hiberbate3.x,目前暂时不要使用hibernate4.0
好吧,那我就不适用4.0.
不过还是想请教大神有没有其他办法解决。
PS:第三篇水文,慢慢坚持把。