javadatabaseeclipsejpaeclipse-oxygen

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?


Solution

  • 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-oxygen-jpa-tooling

    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, i.e. 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:

    eclipse-oxygen-jpa-tooling-contextmenu

    Actually, this only works with a working DB configuration, i.e. (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