Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ IDEA 2016: Please choose persistence unit

I try to atomatic generate entities by IntelliJ IDEA but not success.

error: Please choose presistence unit.

enter image description here

Help me generate entity and mapping files.

like image 809
Do Nhu Vy Avatar asked Jun 29 '16 13:06

Do Nhu Vy


People also ask

How do I enable persistence in IntelliJ?

Right-click a module or a persistence unit, point to Generate Persistence Mapping and select By Database Schema. Select the source and output options and click OK.

How import javax persistence in IntelliJ?

Enable JPA support for an existing project Open the build file in the editor (pom. xml or build. gradle depending on the build tool that you use in your project). Press Ctrl+Shift+O to import the changes.

What is persistent unit?

A persistence unit defines a set of all entity classes that are managed by EntityManager instances in an application. This set of entity classes represents the data contained within a single data store. Persistence units are defined by the persistence.xml configuration file.

Where should persistence xml be located?

xml should be put in the EJB JAR's META-INF directory. If you package the persistence unit as a set of classes in a WAR file, persistence. xml should be located in the WAR file's WEB-INF/classes/META-INF directory.


2 Answers

I've got the similar problem.Here is my solution.

  1. add "JPA" facet.
    open the "Project Structure" window -> click the "Facets" -> click the "add" button -> select "JPA"

  2. add JPA persistence.xml.
    add persistence click "persistence" -> right click your root item in the "persistence" toolbar -> "Generate Persistence Mapping" -> "By Database Schema".

  3. generate entities.
    Step 3
like image 168
Robyn Liu Avatar answered Sep 18 '22 13:09

Robyn Liu


you need add "hibernate.cfg.xml" first

Project Structure -> Modules -> Hibernate add hibernate.cfg.xml

like image 38
Yuechuan Xiao Avatar answered Sep 20 '22 13:09

Yuechuan Xiao