Eclipse 在我的 JPA 项目上报告错误

发布于 2024-12-11 10:37:12 字数 558 浏览 0 评论 0原文

每次我创建 JPA 项目时,Eclipse 都会报告我的项目中有错误,但我不明白为什么会这样。我在下面添加了图像和错误:

在此处输入图像描述

描述资源路径位置类型列“id”无法解析 在表“page”Page.java /BreakpointJPA/src/no/breakpoint/domain 行上 14 JPA问题

描述资源路径位置类型列“标题”不能 桌上解决 “页面”Page.java /BreakpointJPA/src/no/breakpoint/domain 第 18 行 JPA 问题

描述资源路径位置类型主键连接列“id” 无法在表上解决 “页面”Page.java /BreakpointJPA/src/no/breakpoint/domain 第 10 行 JPA 问题

在此处输入图像描述

Each time I make a JPA project Eclipse reports that there are errors in my project but I do not understand why it does so. I added image and errors below:

enter image description here

Description Resource Path Location Type Column "id" cannot be resolved
on table "page" Page.java /BreakpointJPA/src/no/breakpoint/domain line
14 JPA Problem

Description Resource Path Location Type Column "title" cannot be
resolved on table
"page" Page.java /BreakpointJPA/src/no/breakpoint/domain line 18 JPA
Problem

Description Resource Path Location Type Primary key join column "id"
cannot be resolved on table
"page" Page.java /BreakpointJPA/src/no/breakpoint/domain line 10 JPA
Problem

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

格子衫的從容 2024-12-18 10:37:12

我也遇到了同样的问题,我的解决方案是刷新数据库连接。

打开 JPA 视图,找到数据源浏览器。在那里打开数据库连接,连接数据库,点击刷新。然后在文件中进行一些更改并保存它,我在 id 字段中添加了 @Column(name = "") 注释。之后错误消息消失了,我删除了列注释。

问题似乎是 Eclipse 在建立第一个连接后读取数据库表,然后关闭连接。因此,如果您像我一样,在数据库中的第一次连接后进行了一些更改,例如将字段名称从 foo_id 更改为 id,则 Eclipse 不知道这一点并会出现此错误。

I've had the same problem, the solution for me was to refresh the database connection.

Open the JPA view, find the data source explorer. There you open Database Connection, connect with your database, hit refresh. Then make some changes in your file and save it, i added an @Column(name = "") annotation to my id field. After that the error message was gone, and i ereased the Column annotation.

The Problem seems to be that eclipse reads the database tables after establishing the first connection, after that the connection is closed. So if you, like i did, made some changes after this first connection in your database, like changing the field name from foo_id to just id, eclipse didn't know that and comes with this error.

酷到爆炸 2024-12-18 10:37:12

旧线程,但是我遇到了同样的问题并用更快的方法解决了。

  1. 项目属性 --> JPA
  2. 将连接更改为 .点击应用。
  3. 将连接更改为之前的值。点击应用。

希望这对某人有帮助。

Old thread, however I just had the same problem and solved with an even quicker approach.

  1. Project Properties --> JPA
  2. Change connection to . Hit apply.
  3. Change connection to previous value. Hit apply.

Hope this helps someone.

琉璃繁缕 2024-12-18 10:37:12

如果您想轻松解决问题,请阅读本文

您的数据库没有问题。您只需创建一个从 Eclipse 到同一个数据库的新连接,这与我们在将 JPA 功能添加到项目期间所做的相同。

步骤:-
从 mysql 提示符创建一个新数据库。
右键单击 Eclipse/MyEclipse 中的项目,然后转到“属性”。
单击左侧的 Eclipse/MyEclipse 选项卡,然后单击 JPA 子菜单。
然后单击创建新连接。输入新的连接名称。并添加相同的数据库。 (您也可以选择更改数据库,但也可以使用相同的数据库)。
测试连接,然后单击“完成”。
第一次它不会显示新创建的连接名称。只需单击“确定”即可关闭该窗口。

然后,再次右键单击“项目”,然后单击“属性”。现在您可以在该连接下拉列表中看到新创建的连接。选择它并单击“确定”。

你的错误将会消失。

此错误的可能原因:-
每次您使用 persistence.xml 使用任何项目进行连接时,Eclipse 都会创建与数据库的连接,但仅限于第一次。
因此,此后的任何更改,尤其是来自数据库端(表名等)的更改都会从 Eclipse 中引发错误。

谢谢。

Read This if you want to solve your problem easily

There is no problem in your Database. You just have to create a new connection from Eclipse to the same database which we do during Adding JPA capabilities to the Project.

Steps:-
Create a new database from your mysql prompt.
Right click on your Project in Eclipse/MyEclipse, then go to Properties.
Click on Eclipse/MyEclipse tab on the left and then click on JPA sub menu.
Then Click on Create new Connection. Put a new Connection name. And add the same Database. (You can opt to change your database too, but same database will also do).
Test Connection, and click on Finish.
First Time it wont show that newly created Connection name. Just Click Ok to close that Window.

Then, Right Click again on Project and then Click on Propeties. Now you can see your newly created Connection on that Connection drop down list. Selct that and Click OK.

Your Error will vanish.

Possible Reason for this error:-
Eclipse creates connection with you database everytime you connect using any project using persistence.xml, but only for the first time.
So, any changes after that, especially from the database side(table name etc.) will throw an error from Eclipse.

Thank You.

執念 2024-12-18 10:37:12

我也有同样的问题。这是我解决

  1. 刷新连接的 方法
    • 转到数据源浏览器
    • 选择连接并右键单击
    • 选择“刷新”
  2. 清理项目
    • 转到项目菜单
    • 选择干净

I had the same problem. Here is how I solved it

  1. refreshed the connection
    • Go to Data Source Explorer
    • Select connection and right click
    • select Refresh
  2. Clean the project
    • Go t Project menu
    • select clean
瑾兮 2024-12-18 10:37:12

转到数据源资源管理器,断开数据库连接,连接数据库连接后,右键单击您的项目,然后单击验证。

我希望它对你有帮助。

Go to Data Source Explorer, disconnect the database connection, after connect the database connection, right click in your project and click in validate.

I hope it helps you.

尐籹人 2024-12-18 10:37:12

您的项目中是否包含 JPA/JPA2 接口?如果您使用 Maven,则需要包含类的依赖项。我认为它们是因为导入声明中没有出现红线,但为了安全起见,您应该验证它们是否存在。

对于 JPA2 依赖项,您可以使用:

<dependency>
    <groupId>org.hibernate.javax.persistence</groupId>
    <artifactId>hibernate-jpa-2.0-api</artifactId>
    <version>1.0.0.Final</version>
</dependency>

Do you have the JPA/JPA2 interfaces included in your project? If you are using maven, you need to include a dependency for the classes. I assume that they are since there are no red lines appearing in the import declarations, but just to be safe, you should validate that they exist.

For a JPA2 dependency, you can use:

<dependency>
    <groupId>org.hibernate.javax.persistence</groupId>
    <artifactId>hibernate-jpa-2.0-api</artifactId>
    <version>1.0.0.Final</version>
</dependency>
看轻我的陪伴 2024-12-18 10:37:12

你能试试这个吗:

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "id", unique=true, nullable=false)
private int id

Can you try this:

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "id", unique=true, nullable=false)
private int id
×眷恋的温暖 2024-12-18 10:37:12

尝试在 @Column(name="") 的引号内执行代码辅助。或者打开 JPA 详细信息视图并查看列名称组合以查看列选项。 @Table(name="page") 注释上没有验证错误,因此看起来 Eclipse 正在查找页表。

Try doing code assist inside the quotes of @Column(name=""). Or open the JPA Details view and view the column name combo to see the column options. There is no validation error on the @Table(name="page") annotation, so it looks like Eclipse is finding the page table.

所谓喜欢 2024-12-18 10:37:12

注释看起来正确,您确定您的项目类路径正确吗?首先尝试构建没有 id 和 title 字段的实体。

The annotations look correct, are you sure your project classpath is good? try and build the entity without the id and title fields first of all.

痞味浪人 2024-12-18 10:37:12

就我而言,它只是“属性”->“JPA”->“添加连接”中的旧连接。所以刷新没有帮助。当刷新不起作用时,正确数据库的新连接将有所帮助。

In my case it was just old connection in Properties->JPA->Add connection. So refresh will not help. New connection for correct database will help when refresh will not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文