简体   繁体   English

如何将 JPA 工具添加到 Eclipse Oxygen 中的普通 Java 项目?

[英]How to add JPA tooling to a plain Java project in Eclipse Oxygen?

I'm trying to generate JPA entities from database tables in an Eclipse Oxygen Java EE project.我正在尝试从Eclipse Oxygen Java EE 项目中的数据库表生成 JPA 实体。

Problem is I can't find the JPA context menu, nor I can find the JPA (Java Persistence) facet.问题是我找不到 JPA 上下文菜单,也找不到 JPA(Java Persistence)方面。 How do I manage to do that?我该如何做到这一点?

To activate JPA tooling in a fresh Eclipse Java project you need to add a so-called Project Facet , as seen in this screenshot: 要在全新的Eclipse Java项目中激活JPA工具,您需要添加一个所谓的Project Facet ,如此屏幕截图所示:

蚀 - 氧 -  JP-A-工装

First, right-click on your project folder (for which you want to add JPA support). 首先,右键单击项目文件夹(要为其添加JPA支持)。 Next, select 'Project Facets' from the tree navigation and activate the JPA option, as seen in step 2. 接下来,从树导航中选择“Project Facets”并激活JPA选项,如步骤2中所示。

With a fresh Eclipse installation, ie which has never used a JPA provider (via User Library) locally, you will be asked to setup and download a persistence provider implementation. 使用全新的Eclipse安装,即从未在本地使用JPA提供程序(通过用户库),将要求您设置和下载持久性提供程序实现。 This might also apply for new/different workspaces. 这可能也适用于新的/不同的工作空间。


Note well: For the demo project/workspace, displayed within the screenshot, this has already been done and EclipseLink (2.5.2) was selected and downloaded previously. 注意: 对于屏幕截图中显示的演示项目/工作区,这已经完成,之前已选择并下载了EclipseLink(2.5.2)。 It's up to you to configure the persistence provider of your choice depending on your environment. 您可以根据自己的环境配置所选的持久性提供程序。


Finally, click on 'Apply and Close' to finish the basic JPA setup (step 3). 最后,单击“应用并关闭”以完成基本的JPA设置(步骤3)。 Afterwards, you have the necessary tooling to auto-generate entities from existing database tables, as seen in the next screenshot: 之后,您可以使用必要的工具从现有数据库表中自动生成实体,如下一个屏幕截图所示:

蚀 - 氧 -  JP-A-工装文本菜单

Actually, this only works with a working DB configuration, ie (local) database connection. 实际上,这仅适用于工作数据库配置,即(本地)数据库连接。 This can also be configured in the moment you setup the JPA provider and related tooling options, such as JDBC URL and JDBC driver jar file. 这也可以在您设置JPA提供程序和相关工具选项时配置,例如JDBC URL和JDBC驱动程序jar文件。

Hope it helps. 希望能帮助到你。


For documentation purposes: 出于文档目的:

Eclipse Java EE IDE for Web Developers.
Version: Oxygen Release (4.7.0)
Build id: 20170620-1800

Create a driver to connect to a specific database.创建驱动程序以连接到特定数据库。

  1. Select Window> Preferences from the main menu bar.从主菜单栏中选择窗口 > 首选项。
  2. Expand Data Management> Connectivity and select Driver Definitions.展开数据管理> 连接并选择驱动程序定义。
  3. Here you will seen default Driver Defination.Then edit "Other Driver Default"在这里您将看到默认的驱动程序定义。然后编辑“其他驱动程序默认值”
  4. click on properties and add the details of database related properties.单击属性并添加数据库相关属性的详细信息。 Then click ok.然后点击确定。
  5. This operation automatically pick up the related drivers.Then click add and select the vendor from vendor filter.此操作会自动选择相关驱动程序。然后单击添加并从供应商筛选器中选择供应商。
  6. in my case iam using mysql.在我的情况下,我使用 mysql。
  7. Go to project, right click , jpa tools.转到项目,右键单击,jpa 工具。
  8. select connection profile.选择连接配置文件。
  9. check database name and url.检查数据库名称和 url。 [1]: https://i.stack.imgur.com/jbSip.png [2]: https://i.stack.imgur.com/VRg6x.png [3]: https://i.stack.imgur.com/eRhNb.png [4]: https://i.stack.imgur.com/hz705.png [5]: https://i.stack.imgur.com/c8kDI.png [6]: https://i.stack.imgur.com/dzvnq.png [7]: https://i.stack.imgur.com/r6gRN.png [8]: https://i.stack.imgur.com/aTCex.png [1]: https://i.stack.imgur.com/jbSip.png [2]: https://i.stack.imgur.com/VRg6x.png [3]: HTTPS://i.stack。 imgur.com/eRhNb.png [4]: https://i.stack.imgur.com/hz705.png [5]: https://i.stack.imgur.com/c8kDI.png [6]: https ://i.stack.imgur.com/dzvnq.png [7]: https://i.stack.imgur.com/r6gRN.png [8]: https://i.stack.imgur.com/aTCex .png

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM