`
streammoon
  • 浏览: 25293 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Spring data jpa

 
阅读更多
java.lang.ExceptionInInitializerError
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:449)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.txl.app.dao.UserServiceTest.<clinit>(UserServiceTest.java:10)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:400)
at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:275)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.detectPersistenceExceptionTranslators(PersistenceExceptionTranslationInterceptor.java:139)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.<init>(PersistenceExceptionTranslationInterceptor.java:79)
at org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisor.<init>(PersistenceExceptionTranslationAdvisor.java:70)
at org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor.setBeanFactory(PersistenceExceptionTranslationPostProcessor.java:103)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1475)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1443)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
... 10 more
Caused by: java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:629)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:268)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 25 more




错误:删掉JavaEE5 Libraries.
jar:



测试web目录图:





各个文件:

persistence.xml:
<persistence 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_1_0.xsd"
    version="1.0">
    <persistence-unit name="punit" transaction-type="RESOURCE_LOCAL">
   <provider>org.hibernate.ejb.HibernatePersistence</provider> 
  
       <properties>
     
         
       </properties>
    </persistence-unit>
</persistence>



applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa-1.2.xsd
">
   <context:annotation-config/>
      <context:component-scan base-package="com.jpa.app" />
     
      <bean   class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
   
<bean id="entityManagerFactory"    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">   
     <property name="dataSource" ref="dataSource" /> 
     <property name="persistenceXmlLocation" value="classpath:persistence.xml"/>  
    
     <property name="jpaVendorAdapter">         
           <bean   class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">               
                  <property name="database" value="ORACLE" />         
           </bean>       
    </property>
   
   
</bean>

<!-- oracle-->
<bean id="dataSource"    class="org.springframework.jdbc.datasource.DriverManagerDataSource">    
   
    <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl" />
    <property name="username" value="jpatest" />     
   <property name="password" value="123" />    
</bean>

<bean id="transactionManager"   class="org.springframework.orm.jpa.JpaTransactionManager">   
     <property name="entityManagerFactory" ref="entityManagerFactory" />  
</bean>   

<tx:annotation-driven transaction-manager="transactionManager" />  
  
<jpa:repositories base-package="com.jpa.app.dao" entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="transactionManager"/>
</beans>


-----------
Dept.java:

package com.jpa.app.beans;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.springframework.context.annotation.Lazy;
@Entity
@Table(name="t_dept")
@SequenceGenerator(
name="SEQ_DEPT",
sequenceName="SEQ_DEPT"
)
public class Dept implements Serializable{

/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
(strategy=GenerationType.SEQUENCE,generator="SEQ_DEPT")
@Column(name="did")
private Integer did;
private String dname;
public Integer getDid() {
return did;
}
public void setDid(Integer did) {
this.did = did;
}
public String getDname() {
return dname;
}
public void setDname(String dname) {
this.dname = dname;
}


}
----------
DeptService.java:
package com.jpa.app.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jpa.app.beans.Dept;
@Service("deptService")
public class DeptService {
@Autowired
private IDeptDao iUserDao;
public List<Dept> findAll() {
List<Dept> list = iUserDao.findAll();
System.out.println(list);
for(Dept d:list){
System.out.println(d.getDname());
}
return null;
}
}

-------------
IDeptDao.java:
package com.jpa.app.dao;

import java.util.List;

import org.springframework.data.repository.Repository;

import com.jpa.app.beans.Dept;

public interface IDeptDao extends Repository<Dept,Integer>{

List<Dept> findAll();
}


----------
测试类:

public class DeptServiceTest {
private static ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
private static DeptService deptService = (DeptService) context.getBean("deptService");

public static void main(String[] args){
   deptService.findAll();
}
}


以上能够运行成功,主要来源于三处借鉴:
http://www.2cto.com/kf/201207/143587.html

http://wenku.baidu.com/view/319d1162783e0912a2162abf.html

http://wenku.baidu.com/view/394dbe679b6648d7c1c746a4.html

结构是按第一连接来的 ,不过我这边还是跑不起来:
后来采用二连接的jar包结构,报上面的错误。
后又找到三连接。解决问题。

感谢!
  • 大小: 142.7 KB
  • 大小: 32.5 KB
分享到:
评论

相关推荐

    Spring Data JPA中文文档[1.4.3]_springdatajpa_erlang_waitxpf_

    **Spring Data JPA** 是一个基于 **Java** 的开源框架,它是 **Spring Framework** 的一个模块,主要用于简化 **Java Persistence API (JPA)** 的使用。JPA 是 Java 平台上的一个标准,用于管理和持久化应用程序的...

    Spring Data JPA API(Spring Data JPA 开发文档).CHM

    Spring Data JPA API。 Spring Data JPA 开发文档。 官网 Spring Data JPA API。

    Spring Data JPA 笔记

    Spring Data JPA 是一个强大的框架,它简化了Java应用程序与数据库之间的交互,是Spring生态中的重要组成部分。通过使用Spring Data JPA,开发者可以避免编写大量的JPA(Java Persistence API)和SQL代码,专注于...

    spring注解+spring data jpa文档+JPA文档.rar

    Spring框架的核心特性包括依赖注入(DI)和面向切面编程(AOP),并且它还提供了对数据库操作的支持,这主要通过Spring Data JPA和Java Persistence API(JPA)实现。 Spring注解是Spring框架中的一大特色,它极大...

    Spring Data JPA的优点和难点.pdf

    Spring Data JPA是Spring生态中的一个强大ORM框架,它极大地提高了Java开发者在处理数据库操作时的效率。Spring Data JPA的主要优点在于其高度的开发效率、成熟的语法结构以及与Spring框架的紧密集成。 1. **开发...

    Spring Data JPA从入门到精通

    《Spring Data JPA从入门到精通》是一本深入解析Spring Data JPA的书籍,它以Spring Boot框架为核心,旨在帮助读者全面理解并熟练运用Spring Data JPA进行数据库操作。Spring Data JPA是Spring Framework的一个模块...

    手动创建 SpringMvc +SpringDataJpa+Hibernate+ freemarker mavenProject+ 环境切换 webDemo

    在本项目中,我们主要探讨如何手动构建一个基于SpringMVC、Spring Data JPA、Hibernate以及FreeMarker模板引擎的Maven工程,同时实现环境切换功能。这个基础框架为日常开发工作提供了必要的支持。 首先,SpringMVC...

    Spring Data JPA.zip

    **Spring Data JPA 深度解析** Spring Data JPA 是 Spring Framework 的一个重要模块,它为 Java Persistence API (JPA) 提供了便捷的数据访问层。这个框架简化了数据库操作,使得开发人员能够以声明式的方式处理...

    Spring Data JPA中文文档[1.4.3].zip

    Spring Data JPA是Java开发中的一个关键框架,它简化了与关系型数据库的交互,特别是基于Java Persistence API (JPA)。这个框架是Spring生态系统的组成部分,为开发者提供了声明式数据访问的方式,允许通过简单的...

    spring data jpa 教程

    Spring Data JPA 是一个基于 Java 的开源框架,它属于 Spring Data 家族的一部分,旨在简化 Java 应用中的数据访问层代码,特别针对基于 JPA(Java Persistence API)的数据持久化操作。本教程将详细介绍 Spring ...

    Spring Data JPA Demo

    Spring Data JPA 是一个强大的框架,它简化了与Java Persistence API (JPA) 的交互,JPA 是Java 开发者用来管理和持久化应用程序数据的一种标准。在这个“Spring Data JPA Demo”项目中,我们将深入探讨如何利用...

    springdatajpa.pdf

    SpringDataJPA是Spring框架中用于简化数据持久层操作的一个模块,它基于Java持久层API(Java Persistence API,JPA)标准。在实际的项目开发中,SpringDataJPA能够极大程度上减少我们对于数据访问层代码的编写工作。...

    使用 SpringBoot + SpringDataJPa 设计通用的权限管理系统,适合管理系统快速开发迭代,可用于开发模板

    使用 SpringBoot + SpringDataJPa 设计通用的权限管理系统,适合管理系统快速开发迭代,可用于开发模板,项目经过测试,可完美运行! 使用 SpringBoot + SpringDataJPa 设计通用的权限管理系统,适合管理系统快速...

    spring data jpa + spring + json demo

    【标题】"spring data jpa + spring + json demo"揭示了这个项目是关于使用Spring Data JPA、Spring框架以及JSON处理的一个示例应用。Spring Data JPA是Spring框架的一个模块,它简化了JPA(Java Persistence API)...

    其实spring data jpa比mybatis更好用.zip_JPA mybatis

    标题"其实spring data jpa比mybatis更好用.zip_JPA mybatis"指出本主题将探讨Spring Data JPA与MyBatis之间的比较,并暗示在某些方面,Spring Data JPA可能更为优越。描述中提到"全方位介绍jpa",表明内容将深入讲解...

    Spring Data JPA入门项目02

    在本项目"Spring Data JPA入门项目02"中,我们将深入探讨如何使用Spring Data JPA进行查询操作,包括排序和分页。Spring Data JPA是Spring Framework的一个模块,它为Java Persistence API (JPA) 提供了一种更加便捷...

    Spring Boot整合SpringDataJPA

    Spring Data JPA是Spring生态系统中的一个重要组件,它为开发者提供了与JPA(Java Persistence API)交互的简化接口,极大地提高了数据访问的效率。本教程将深入探讨如何在Spring Boot项目中整合Spring Data JPA,...

    spring data jpa简单案例

    **Spring Data JPA 简单案例** Spring Data JPA 是 Spring 框架的一个模块,它为使用 JPA(Java Persistence API)提供了强大的支持,简化了数据访问层的开发。通过使用 Spring Data JPA,我们可以避免编写大量重复...

Global site tag (gtag.js) - Google Analytics