IntelliJ IDEA 2016: Please choose persistence unit - java

I try to atomatic generate entities by IntelliJ IDEA but not success.
error: Please choose presistence unit.
Help me generate entity and mapping files.

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".
generate entities.

you need add "hibernate.cfg.xml" first
Project Structure -> Modules -> Hibernate add hibernate.cfg.xml

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.
image 3
With the same window still open, select "Schemas" and make sure you have selected your DB of choice. WELLNESS_APP in my case. Now hit Ok at the bottom.
image 4
Back in the "Import Database Schema" window choose your package from the dropdown. Then, scroll through the "Database Schema Mapping" section until you find your table(s) of choice. Select them and verify the mapping is correct. Then, select the "Add to Persistence Unit" checkbox at the bottom, hit the "+" icon to the right of it, and give it a name. Verify the rest of your selections at the bottom match mine & then you're good to go. The result should be an addition to your persistence.xml that somewhat resembles what I've screenshotted.
image 5
image 5
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!

Related

Can't create project in sonar

I'm having trouble creating a project in my sonarqube instance - it's like there are projects already created that I cannot see.
I login as the admin user, go to the Administration -> Projects -> Projects Management page, and then click Create Project.
I give it a name, and then when I type in my maven project name in the key field, e.g. au.com.foo:project-bar and click create, I get the message that
"Could not create Project, key already exists: au.com.foo:project-bar"
Thing is, when I look at the list of all projects on that project management screen, there is no project with that key. There is also nothing under Provisioned and nothing listed under Ghosts either.
What gives? I would have thought if there was a previous unsuccessful project with that key it would have been listed under the ghosts section anyhow. I'm also definitely logged in as admin here, so should see everything?
In the end, I found a workaround - not a particularly nice one, mind you. I opened up the Sonar database and had a look in the PROJECTS table:
select * from projects where kee like 'au.com.foo:project-bar%'
This revealed a couple of old entries from a previously (unsuccessful, I guess - there was no files indexed against these entries) attempt to analyse the project. Doing a delete from the table of these entries then enabled me to create the project in Sonar again.
Why the entries didn't render on the UI in the first place is anyone's guess.

Java - Hibernate Tools Query property should be explicitly set for Query Exporter?

i learn Hibernate by follow step here.
But I got this error:
Query property should be explicitly set for Query Exporter
when run Hibernate Code Generation( The last step). Do anyone know it?
Don't select "HQL Query Execution Exporter" in "Hibernate Code Generation Configuration" "Exports" tab.
It works for me.
I think you shoud set the reveng.xml file.
In the Hibernate Generate Code Configuration window, click the Setup button at the "reveng.xml" line.
Then choose "Create new...", select the location for the configuration file you will create.
Click "refresh", you will see your schema so you can choose what table you want to reverse engineer.
I do not have enough reputation to post screenshots, I am sorry.
I hope this helps.

How can I load a predefined rule set to a sonar profile

i have a local sonar server running. i would like to create a new profile with a set of rules that were predefined by someone else. i have the XML file containing all the rules.
is there a way to upload the XML file to the profile and not define the rules manually?
thanks
Make sure you are logged into Sonar.
Click on Quality Profiles in the top navigation bar, then click on "Restore Profile" on the right hand side under the search bar. Make sure you have all the applicable quality plugins that the export is using or the restore will choke.
May be a bit old thread but worth answering this question with exact steps as I struggled alot with this problem.
Though its a hacky way to import rulebook from prod to your local. But it works and can save valuable time.
Here are the steps:
Login to SonarQube as admin.
Create a new Quality Profile as below:
Download the default xml from local sonarqube by clicking on Backup button. Lets call this file local-rulebook.xml
Open both the prod-rulebook.xml file & local-rulebook.xml in notepad.
Delete the selected part from local-rulebook.xml & replace with the content from prod-rulebook.xml. Save the file.
P.S: Do not change the value of <profile><name>{yourProfileName}</name>.
Go back to sonarQube and Click Restore at top-right corner of the screen.
Import the newly updated file
Change the default profile type.
Congrats you successfully imported the prod-rulebook.xml to your local sonarqube.

ContainerSelectionDialog in Java

I develop my first plugin - 2 questions:
I'm using ContainerSelectionDialog dialog in my eclipse plugin to give my user the option to choose project.
but it show me the project and the folder in them, I want to show the user only the project with out option to expend the project and choose folder,
how can I do it?
when user select my wizard (new->other->myWizard) i want to know which project in the packageexplorer it select ( like you have in new class that it know which project is selectd)
Thanks!!
You can use a org.eclipse.ui.dialogs.ElementListSelectionDialog and call setElements() on it. The data you pass to setElements() should be an array of IProject instances; one way to obtain that is via org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getProjects()
Note A: IWorkspaceRoot.getProjects() will return all projects, including closed ones, so depending on your needs you may want to filter that list before passing it to the dialog (look at IProject.isAccessible())
Note B: You can use org.eclipse.ui.model.WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider() for the dialog's labelProvider.

remove component from initComponent()

i am using netBeans editor to create desktop application , i did something wrong that generate
three line of code in the initComponent() method related to connection with database. Then i removed the lines by opening the .java file in txt editor , but one of them keep coming back when i do anything with netBeans editor , So i want to delete this line from the netbeans itself . this is the line
historyList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : ((javax.persistence.Query)null).getResultList();
and this is its declaration
private java.util.List<idetect.History> historyList;
Use the Inspector to find the query component and delete it
Window->Navigating->Inspector menu in Netbeans IDE 7.0.1
I think the simplest way to edit the automatically generated code is to do the following;
If you go to the Design panel of your class in Netbeans (where you can see the constructed GUI) then all of the elements you have added will be in the Navigator Pane, which is usually located in the bottom left.
If you can't see the Navigator pane then ctrl+7 brings it up.
Find the element you wish to remove in the list, right click and click Refactor > Safely Delete.
Personally if I need to write a GUI in Netbeans I use it to generate the boring stuff, and then paste the generated code into a different editor to write my actions.
The java source is regenerated automatically from the matching .form file. You need to delete the component either from the GUI editor itself or from the form file(which is not visible in NetBeans).
When you've opened a GUI form in NetBeans its components are visible in a tree in the Inspector tab in the lower left part of your screen. You can select the component you want to delete there, right click and select "Delete".
Easiest Solution: Open the .java-file in your project-directory containing your "initComponent"-Method with another text-editing Program (e.g. notepad++) and delete the lines you want to remove. It worked out for me.

Categories

Resources