Module defaults to wrong database and gives compile warnings
已回答
I use multiple databases. I can define them in the the Database tool, connect to them and do ad-hoc queries just fine.
But I can't find how to tell IntelliJ IDEA which databases are used by a given module. On occasion I see pulldowns on my DaoImpl but it does not refer to the right databases and the result is compiler warnings for the columns and tables... even though they are valid.
How do I fix this?
请先登录再写评论。
Please check https://www.jetbrains.com/help/idea/persistence-tool-window.html#assign_data_source.
I don't see the options that document mentions when I right-click.
In case it is relevant:
- Built using Spring Boot and Maven.
- In the DAO I am using old-style JDBC via the Spring jdbcTemplate. No ORM.
This is what I see at the top of the DaoImpl. The pulldowns DO NOT show options for the database used by this module. It shows options for a database used by a different module.
These are the databases defined in the tool. Both work properly ad-hoc. I should probably mention that by the time the project is complete there might be many more databases used by various modules.
This is what I see when I right-click the module:
Please report at https://youtrack.jetbrains.com/newIssue?project=IDEA with a small sample project to reproduce this issue.
Sadly... I've tried the formal support many times for various issues and very rarely I got any usable answers, instead I found myself wasting my time on useless runarounds. So I gave up on them. Creating a sample project would be time consuming and probably achieve nothing. And this should be a pretty straightforward issue.
Believe it or not I get much better answers from this community site.
As an alternative... is there a way to tell IntelliJ IDEA to NOT even attempt to validate SQL and suppress the SQL compiler errors instead? The feature would be nice, but it is just too much of a pain to get it working.
You can disable SQL injections/inspections in the settings.
See https://www.jetbrains.com/help/idea/disabling-and-enabling-inspections.html#suppress-in-editor.
Doesn't look like a straightforward issue as I was not able to find anyone else reporting it in all these years.
People might not report it in part because most people work with only one database, and in part because they are frustrated at the failures of support. No better way to avoid providing support than by giving links to "solutions" that no longer match the current IDE. I would bet it also frustrates support people.
For example, even to just disable, the link you just gave says to place the cursor on the element with the problem hit Alt-Enter and then Disable the inspection. But Alt-Enter has nothing that mentions inspections.
EDIT:
It is an amazing IDE, but it is quite un-intuittive and its documentation is horribly out of date, so that most of the time the documentation hinders more than it helps.
Alt+Enter should display the current inspection that applies to the highlighted code and from the right arrow sub-menu you can navigate to its settings or disable it, this documentation is accurate: