0

我的学校有一个小的 Java 项目。我将 Eclipse Neon 与 JPA 图表编辑器和 JavaFX 一起使用。问题 -> 当我建立与数据库的连接时,一切正常(结构:项目 -> META-INF -> persistence.xml,通过 JPA 生成)。我没有更改persistence.xml中的文件夹名称或其他内容,我只在Main-class中工作并添加了一个新的DAO-class。现在我收到此错误消息,但不明白为什么。

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="Kursverwaltung" transaction-type="RESOURCE_LOCAL">
<class>model.Course</class>
        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
            <property name="javax.persistence.jdbc.user" value="*right username*"/>
            <property name="javax.persistence.jdbc.password" value="*right password*"/>
            <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
            <property name="hibernate.hbm2ddl.auto" value="create"/>
        </properties>
    </persistence-unit>
</persistence>

那么项目怎么能找不到文件,该文件有效并且我没有更改文件夹或文件名......或任何可能与路径有关的东西?我只找到了路径错误的答案,但是结构是通过 JPA 创建的并且有效,所以我认为这不应该是问题。

感谢您的帮助,如果语法不太好,我们深表歉意。

4

1 回答 1

0

I came across this post while searching for clues as I had gotten the same error message. I thought this answer was helpful. It is easy to typo as things get more complicated.

But I'm pretty sure my situation was free of typos. I think another possible cause is that Eclipse just gets messed up sometimes, if one is doing things that are a little unusual that affect the file structure or build configuration.

Sometimes the best thing to do (after trying a Refresh, a Project clean and closing and restarting Eclipse) is to start fresh and build a new project.

I started a new project and everything worked fine. I compared the web.pom and persistence.xml and they were both identical to the failing project, except for the different project names. Maven libraries were the same. Classes were the same. Maybe I overlooked something, but if the error is something internal in Eclipse, starting fresh is probably the best.

于 2021-01-24T08:23:01.263 回答