Intellij IDEA: specify datasource for JPA validation

前端 未结 8 1537
无人共我
无人共我 2020-12-07 16:20

I have a Spring project for a small web app set up in Intellij IDEA.

It uses JPA on top of Hibernate for the persistence layer. The datasource (MySQL) is defined in

相关标签:
8条回答
  • 2020-12-07 17:22

    I finally found out how to do this.

    The key is the "persistence" tool window. Apparently it is made available after you add the JPA facet, but is a separate tool window.

    To open it : menu "view" -> Tool Windows -> Persistence

    In this window you see your application with the different persistence related elements (I see persistence.xml, entityManagerFactory from Spring context, and myUnit which I don't know where it comes from.

    Here you can right-click on any element and choose "Assign data source".

    This opens a pop-up dialog with a small table containing you persistence elements on the left column and the data source assigned to it on the right column. You can assign a datasource from the "Database" window in there, so I picked the datasource I had configured for my MySQL DB and voilà, the validation errors went away.

    But if I enter a wrong table or column name, I still get an error, which is pretty neat.

    0 讨论(0)
  • 2020-12-07 17:23

    On top of setting a data source like others have mentioned, in order to clear these false errors, in the Database panel, I had to go to settings, Schemas & Tables tab, and hit the checkbox left of the "information_schema" table for my database.

    0 讨论(0)
提交回复
热议问题