Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jpa 没有名为MyUnit的EntityManager的持久性提供程序,但有一个_Jpa - Fatal编程技术网

Jpa 没有名为MyUnit的EntityManager的持久性提供程序,但有一个

Jpa 没有名为MyUnit的EntityManager的持久性提供程序,但有一个,jpa,Jpa,我得到这个错误: javax.persistence.PersistenceException: No Persistence provider for EntityManager named MyUnit javax.persistence.PersistenceException: No Persistence provider for EntityManager named MyUnit 但是设置应该是正确的。我不能再了解这个世界了 这是一个Maven项目: <project x

我得到这个错误:

javax.persistence.PersistenceException: No Persistence provider for EntityManager named MyUnit
javax.persistence.PersistenceException: No Persistence provider for EntityManager named MyUnit
但是设置应该是正确的。我不能再了解这个世界了

这是一个Maven项目:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MyGroupID</groupId>
<artifactId>MyArtifactID</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>

<name>MyProject Maven Webapp</name>

<build>
    <finalName>MyProject</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.3.168</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.2.1.Final</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>org.jdom</groupId>
        <artifactId>jdom2</artifactId>
        <version>2.0.4</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>1.1.2</version>
    </dependency>
</dependencies>
</project>
下面是我打开实体管理器的类:

public class MyBean implements Serializable {

    private List<String> titles = null

    public List<String> getTitles() {
    EntityManagerFactory factory = Persistence.createEntityManagerFactory("MyUnit");
    EntityManager em = factory.createEntityManager();

    Query query = em.createQuery("SELECT title FROM Bla");

    titles = query.getResultList();

    return titles;
}
公共类MyBean实现可序列化{
私有列表标题=null
公共列表getTitles(){
EntityManagerFactory=Persistence.createEntityManagerFactory(“MyUnit”);
EntityManager em=factory.createEntityManager();
Query Query=em.createQuery(“从Bla中选择标题”);
titles=query.getResultList();
返回标题;
}
}

我真的不知道这里有什么问题。我已经在家里的电脑上运行了。
在我的笔记本电脑上(同一个项目!)它不工作….

请检查META-INF/persistence.xml是否真的复制到了您的输出文件夹中?MyBean类真的在包“sample.beans”中吗?是的。一切正常…命令行上没有可能有用的进一步调试输出(嵌套异常消息等)?不,这是唯一的异常。。。我快疯了…粘贴的persistence.xml文件无效:缺少关闭
javax.persistence.PersistenceException: No Persistence provider for EntityManager named MyUnit
public class MyBean implements Serializable {

    private List<String> titles = null

    public List<String> getTitles() {
    EntityManagerFactory factory = Persistence.createEntityManagerFactory("MyUnit");
    EntityManager em = factory.createEntityManager();

    Query query = em.createQuery("SELECT title FROM Bla");

    titles = query.getResultList();

    return titles;
}