“线程中的异常”;“主要”;javax.persistence.PersistenceException:没有名为lanceurApplication的EntityManager的持久性提供程序

“线程中的异常”;“主要”;javax.persistence.PersistenceException:没有名为lanceurApplication的EntityManager的持久性提供程序,java,hibernate,jpa,oracle11g,spring-3,Java,Hibernate,Jpa,Oracle11g,Spring 3,我正在尝试使用JPA和Hibernate为Java项目设置持久性。我的数据库使用Oracle 11g express。 我已经讨论这个问题好几个小时了,但无论我做什么,当我尝试创建EntityManagerFactory时,我总是会遇到这个异常:我发现了很多关于这个异常的类似问题,但我无法找到解决方案。我做错了什么 详细内容: 我得到的错误是: Exception in thread "main" javax.persistence.PersistenceException: No Persis

我正在尝试使用JPA和Hibernate为Java项目设置持久性。我的数据库使用Oracle 11g express。 我已经讨论这个问题好几个小时了,但无论我做什么,当我尝试创建EntityManagerFactory时,我总是会遇到这个异常:我发现了很多关于这个异常的类似问题,但我无法找到解决方案。我做错了什么

详细内容:

我得到的错误是:

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named lanceurApplication
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at ap.s.tn.test.Main.main(Main.java:15)
persistence.xml

    <?xml version="1.0" encoding="UTF-8"?>
<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="lanceurApplication">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>ap.s.tn.beans.Adresse</class>
    <properties>
    <property name="hibernate.hbm2ddl.auto" value="create"/>
    <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/>
    <property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
    <property name="hibernate.connection.username" value="appACTEL"/>
    <property name="hibernate.connection.password" value="appACTEL"/>
    <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
    </properties>
    </persistence-unit>
</persistence>
adrese.java

    package ap.s.tn.beans;

import java.io.Serializable;
import java.lang.String;
import javax.persistence.*;

/**
 * Entity implementation class for Entity: Adresse
 *
 */
@Entity

public class Adresse implements Serializable {


    private int id_adresse;
    private String rue;
    private String ville;
    private String pays;
    private static final long serialVersionUID = 1L;

    public Adresse() {
        super();
    }   
    @Id  
    @GeneratedValue(strategy=GenerationType.AUTO)
    public int getId_adresse() {
        return this.id_adresse;
    }

    public void setId_adresse(int id_adresse) {
        this.id_adresse = id_adresse;
    }   
    public String getRue() {
        return this.rue;
    }

    public void setRue(String rue) {
        this.rue = rue;
    }   
    public String getVille() {
        return this.ville;
    }

    public void setVille(String ville) {
        this.ville = ville;
    }   
    public String getPays() {
        return this.pays;
    }

    public void setPays(String pays) {
        this.pays = pays;
    }

}

1-删除所有库jar

2-再次添加它们属性->Java构建路径->添加JAR

3-项目->清洁

4-使用spring3进行修改

adrese.java:

package com.springJPA.domain;

import java.io.Serializable;
import java.lang.String;
import javax.persistence.*;

/**
 * Entity implementation class for Entity: Adresse
 *
 */
@Entity

public class Adresse implements Serializable {


    private int id_adresse;
    private String rue;
    private String ville;
    private String pays;
    private static final long serialVersionUID = 1L;

    public Adresse() {
        super();
    }   
    @Id  
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "id_Sequence_adresse")
    @SequenceGenerator(name = "id_Sequence_adresse", sequenceName = "ID_SEQ_ADRESSE")
    public int getId_adresse() {
        return this.id_adresse;
    }

    public void setId_adresse(int id_adresse) {
        this.id_adresse = id_adresse;
    }   
    public String getRue() {
        return this.rue;
    }

    public void setRue(String rue) {
        this.rue = rue;
    }   
    public String getVille() {
        return this.ville;
    }

    public void setVille(String ville) {
        this.ville = ville;
    }   
    public String getPays() {
        return this.pays;
    }

    public void setPays(String pays) {
        this.pays = pays;
    }

}
Main.java:

   package com.springJPA.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.springJPA.domain.Adresse;
import com.springJPA.domain.Utilisateur;
import com.springJPA.service.AdresseService;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Utilisateur utilisateur = new Utilisateur();

        //--------
        Adresse adresse = new Adresse();
        adresse.setRue("kantawi");
        adresse.setVille("Sousse");
        adresse.setPays("Tunisie");
        //--------

        ApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml");
        AdresseService adrService = (AdresseService) context.getBean("adrService");
        adrService.ajoutAdresse(adresse);
    }

}
MyEntityManagerFactory.java:

package com.springJPA.util;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.springframework.stereotype.Component;

@Component("myEMF")
public class MyEntityManagerFactory {
    private EntityManager entityManager;
    private String unitName = "SpringJPA";

    public EntityManager getEntityManager() {
        if(entityManager == null){
        EntityManagerFactory emf = Persistence.createEntityManagerFactory(unitName);
        entityManager = emf.createEntityManager();
        }
        return entityManager;
    }

    public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

    public String getUnitName() {
        return unitName;
    }

    public void setUnitName(String unitName) {
        this.unitName = unitName;
    }

}
TransactionSpect.java:

package com.springJPA.util;


public class TransactionAspect {


    private MyEntityManagerFactory entityManagerFactory;

    public void begin(){
        entityManagerFactory.getEntityManager().getTransaction().begin();
    }

    public void commit(){
        entityManagerFactory.getEntityManager().getTransaction().commit();
    }

    public MyEntityManagerFactory getEntityManagerFactory() {
        return entityManagerFactory;
    }
    public void setEntityManagerFactory(MyEntityManagerFactory entityManagerFactory) {
        this.entityManagerFactory = entityManagerFactory;
    }

}
application-context.xml:

<?xml version="1.0" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.springJPA.service"/>
<context:component-scan base-package="com.springJPA.util"/>
<bean id="tr" class="com.springJPA.util.TransactionAspect">
    <property name="entityManagerFactory" ref="myEMF"/>
</bean>

<aop:config>
    <aop:pointcut expression="execution(* com.springJPA.service.AdresseService.*(..))" id="adrPC"/>
    <aop:pointcut expression="execution(* com.springJPA.service.UtilisateurService.*(..))" id="utlPC"/>
    <aop:aspect ref="tr">
     <aop:before pointcut-ref="adrPC" method="begin"></aop:before>
     <aop:after pointcut-ref="adrPC" method="commit"></aop:after>

     <aop:before pointcut-ref="utlPC" method="begin"></aop:before>
     <aop:after pointcut-ref="utlPC" method="commit"></aop:after>       
    </aop:aspect>
 </aop:config>

</beans>

persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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="SpringJPA" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>com.springJPA.domain.Adresse</class>
    <class>com.springJPA.domain.Utilisateur</class>
    <properties>
    <property name="hibernate.archive.autodetection" value="class" />
    <property name="hibernate.dialect" value="com.mysema.query.jpa.support.ExtendedOracleDialect" />
    <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" />
    <property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:xe" />
    <property name="hibernate.connection.username" value="appACTEL" />
    <property name="hibernate.connection.password" value="appACTEL" />
    <property name="hibernate.flushMode" value="FLUSH_AUTO" />
    <property name="hibernate.hbm2ddl.auto" value="create" />
    <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
    </properties>
    </persistence-unit>
</persistence>

org.hibernate.ejb.HibernatePersistence
com.springJPA.domain.adrese
com.springJPA.domain.usilizateur

1-删除所有库jar

2-再次添加它们属性->Java构建路径->添加JAR

3-项目->清洁

4-使用spring3进行修改

adrese.java:

package com.springJPA.domain;

import java.io.Serializable;
import java.lang.String;
import javax.persistence.*;

/**
 * Entity implementation class for Entity: Adresse
 *
 */
@Entity

public class Adresse implements Serializable {


    private int id_adresse;
    private String rue;
    private String ville;
    private String pays;
    private static final long serialVersionUID = 1L;

    public Adresse() {
        super();
    }   
    @Id  
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "id_Sequence_adresse")
    @SequenceGenerator(name = "id_Sequence_adresse", sequenceName = "ID_SEQ_ADRESSE")
    public int getId_adresse() {
        return this.id_adresse;
    }

    public void setId_adresse(int id_adresse) {
        this.id_adresse = id_adresse;
    }   
    public String getRue() {
        return this.rue;
    }

    public void setRue(String rue) {
        this.rue = rue;
    }   
    public String getVille() {
        return this.ville;
    }

    public void setVille(String ville) {
        this.ville = ville;
    }   
    public String getPays() {
        return this.pays;
    }

    public void setPays(String pays) {
        this.pays = pays;
    }

}
Main.java:

   package com.springJPA.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.springJPA.domain.Adresse;
import com.springJPA.domain.Utilisateur;
import com.springJPA.service.AdresseService;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Utilisateur utilisateur = new Utilisateur();

        //--------
        Adresse adresse = new Adresse();
        adresse.setRue("kantawi");
        adresse.setVille("Sousse");
        adresse.setPays("Tunisie");
        //--------

        ApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml");
        AdresseService adrService = (AdresseService) context.getBean("adrService");
        adrService.ajoutAdresse(adresse);
    }

}
MyEntityManagerFactory.java:

package com.springJPA.util;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.springframework.stereotype.Component;

@Component("myEMF")
public class MyEntityManagerFactory {
    private EntityManager entityManager;
    private String unitName = "SpringJPA";

    public EntityManager getEntityManager() {
        if(entityManager == null){
        EntityManagerFactory emf = Persistence.createEntityManagerFactory(unitName);
        entityManager = emf.createEntityManager();
        }
        return entityManager;
    }

    public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

    public String getUnitName() {
        return unitName;
    }

    public void setUnitName(String unitName) {
        this.unitName = unitName;
    }

}
TransactionSpect.java:

package com.springJPA.util;


public class TransactionAspect {


    private MyEntityManagerFactory entityManagerFactory;

    public void begin(){
        entityManagerFactory.getEntityManager().getTransaction().begin();
    }

    public void commit(){
        entityManagerFactory.getEntityManager().getTransaction().commit();
    }

    public MyEntityManagerFactory getEntityManagerFactory() {
        return entityManagerFactory;
    }
    public void setEntityManagerFactory(MyEntityManagerFactory entityManagerFactory) {
        this.entityManagerFactory = entityManagerFactory;
    }

}
application-context.xml:

<?xml version="1.0" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.springJPA.service"/>
<context:component-scan base-package="com.springJPA.util"/>
<bean id="tr" class="com.springJPA.util.TransactionAspect">
    <property name="entityManagerFactory" ref="myEMF"/>
</bean>

<aop:config>
    <aop:pointcut expression="execution(* com.springJPA.service.AdresseService.*(..))" id="adrPC"/>
    <aop:pointcut expression="execution(* com.springJPA.service.UtilisateurService.*(..))" id="utlPC"/>
    <aop:aspect ref="tr">
     <aop:before pointcut-ref="adrPC" method="begin"></aop:before>
     <aop:after pointcut-ref="adrPC" method="commit"></aop:after>

     <aop:before pointcut-ref="utlPC" method="begin"></aop:before>
     <aop:after pointcut-ref="utlPC" method="commit"></aop:after>       
    </aop:aspect>
 </aop:config>

</beans>

persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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="SpringJPA" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>com.springJPA.domain.Adresse</class>
    <class>com.springJPA.domain.Utilisateur</class>
    <properties>
    <property name="hibernate.archive.autodetection" value="class" />
    <property name="hibernate.dialect" value="com.mysema.query.jpa.support.ExtendedOracleDialect" />
    <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" />
    <property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:xe" />
    <property name="hibernate.connection.username" value="appACTEL" />
    <property name="hibernate.connection.password" value="appACTEL" />
    <property name="hibernate.flushMode" value="FLUSH_AUTO" />
    <property name="hibernate.hbm2ddl.auto" value="create" />
    <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
    </properties>
    </persistence-unit>
</persistence>

org.hibernate.ejb.HibernatePersistence
com.springJPA.domain.adrese
com.springJPA.domain.usilizateur

您的persistence.xml是否在META-INF文件夹中?是的,它在META-INF文件夹中。问题不在META-INF文件夹中。您的类路径中是否有JDBC驱动程序?类似于
ojdbc6.jar
?是的,META-INF文件夹中有一个JDBC驱动程序ojdc6.jar您的persistence.xml吗?是的,它在META-INF文件夹中。问题不在META-INF文件夹中。您的类路径中有JDBC驱动程序吗?类似于
ojdbc6.jar
?是的,有一个JDBC驱动程序ojdc6.jar为什么有两种声明的方言?为什么有两种声明的方言?