日期:2014-05-19  浏览次数:20790 次

EntityManagerFactory配置问题
我的EntityManagerFactory配置
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
<property name="loadTimeWeaver">
          <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
    </property>
</bean> 
persistence.xml
<?xml version="1.0"?>
<persistence version="2.0" 
xmlns="http://java.sun.com/xml/ns/persistence" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="itcast" transaction-type="RESOURCE_LOCAL">
   <provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
         <property name="hibernate.max_fetch_depth" value="3"/>
         <property name="hibernate.hbm2ddl.auto" value="update"/>
     <property name="hibernate.jdbc.fetch_size" value="18"/>
     <property name="hibernate.jdbc.batch_size" value="10"/>
     <property name="hibernate.show_sql" value="false"/>
     <property name="hibernate.format_sql" value="false"/> 
      </properties>
  </persistence-unit>
</persistence>
结果报错
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [beans.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
请高手解答下什么原因?

------解决方案--------------------
缺包了吧。 jpa的实现呢?

ejb3-persistence-1.0.2.GA.jar

上网搜索
------解决方案--------------------
不是缺少了包,反而可能是多了jpa包,极有可能是项目里面引了一个jpa包,hibernate又自带了一个,且版本不一样。
仅是猜测,可作为一种思路。
------解决方案--------------------
应该是你的服务器自带的包和你开发工具中的包之间冲突了。
------解决方案--------------------
我到spring community上面看到上面说这是spring对jpa2.0支持的问题,spring3.1应该会解决。
还是谢谢大家
------解决方案--------------------
希望对大家有用,不要为同样的问题纠结
------解决方案--------------------
不是spring的问题,而是hibernate的有些jar与javaee的jar文件冲突了