简体   繁体   中英

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.

Problem is I can't find the JPA context menu, nor I can find the JPA (Java Persistence) facet. 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:

蚀 - 氧 -  JP-A-工装

First, right-click on your project folder (for which you want to add JPA support). Next, select 'Project Facets' from the tree navigation and activate the JPA option, as seen in step 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. 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. 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). 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.

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.
  7. Go to project, right click , jpa tools.
  8. select connection profile.
  9. check database name and 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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