Reputation: 52516
I try to atomatic generate entities by IntelliJ IDEA but not success.
error: Please choose presistence unit.
Help me generate entity and mapping files.
Upvotes: 11
Views: 25202
Reputation: 11
The top voted answer does a decent job at getting you most of the way there. However, I was having some trouble on step 3. In summary:
Follow steps one and two in that post. Once you've done that and you have a persistence.xml file under the following path: src/main/resources/META-INF/persistence.xml , you will need to map your entity.
Find the "Persistence" toolbar within your IntelliJ IDE. Attached in the below screenshot is where mine was located. image 1
Right click on the root of your persistence. For me this was "Well-Being-App" (this is a personal project). Select: Generate Persistence Mapping > By Database Schema. This will open the window that is shown in step 3 of the top post. image 2
In this window you will need to do a few things. First, connect to your DB instance. I have MySQL installed locally so I was able to click the ellipsis next to "Choose Data Source", hit the "+" icon in the top left of the new window, select MySQL (in my case), supply your username and password in the input fields, give it a URL (likely to be jdbc:mysql://localhost:3306) and hit "Test Connection" at the bottom. If you get a success window, you've done everything right.
Now, I'm quite new to all this but from my understanding, this is a process that will need to be undergone every time you decide to create, update, or delete your DB entities. I hope that is not the case, so if anyone uncovers a setting or preference that handles this for you, please let me know. Best of luck!
Upvotes: 1
Reputation: 86
you need add "hibernate.cfg.xml" first
Project Structure -> Modules -> Hibernate add hibernate.cfg.xml
Upvotes: 4
Reputation: 241
I've got the similar problem.Here is my solution.
add "JPA" facet.
open the "Project Structure" window -> click the "Facets" -> click the "add" button -> select "JPA"
add JPA persistence.xml.
click "persistence" -> right click your root item in the "persistence" toolbar -> "Generate Persistence Mapping" -> "By Database Schema".
Upvotes: 24