Cannot get JPA Query console to work in SpringBoot project
I have a Spring Boot project using spring-data-jpa & Hibernate. The code runs successfully, but now I'm trying to configure the JPA console to test some queries, and even the most simple query fails.
It seems that what currently fails, is trying to display query output. When a query produces no output, there's no error, just an empty result tab.
When there is any output, then I get an error:
jpa-ql> select c from Customer c
[2017-10-09 11:23:48] com.intellij.openapi.application.ex.ApplicationUtil$CannotRunReadActionException
[2017-10-09 11:23:48] at com.intellij.openapi.application.impl.ReadMostlyRWLock.a(ReadMostlyRWLock.java:126)
[2017-10-09 11:23:48] at com.intellij.openapi.application.impl.ReadMostlyRWLock.isReadLockedByThisThread(ReadMostlyRWLock.java:89)
[2017-10-09 11:23:48] at com.intellij.openapi.application.impl.ApplicationImpl.isReadAccessAllowed(ApplicationImpl.java:1086)
[2017-10-09 11:23:48] at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1141)
[2017-10-09 11:23:48] at com.intellij.concurrency.ApplierCompleter.a(ApplierCompleter.java:105)
[2017-10-09 11:23:48] at com.intellij.openapi.progress.impl.CoreProgressManager.a(CoreProgressManager.java:548)
[2017-10-09 11:23:48] at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:493)
[2017-10-09 11:23:48] at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:94)
[2017-10-09 11:23:48] at com.intellij.concurrency.ApplierCompleter.b(ApplierCompleter.java:116)
To get to this point, I already had to go through several hoops none of which was anyhow obvious... So please allow me the diversion to explain how I got to my current state.
The project is a Spring Boot project using (currently) Spring Boot 1.5.7 and Spring Data JPA with Hibernate 5.2.11. All code is written in Kotlin, there's no Java code, using the all-open and no-args plugins. The build tool is Gradle (3.1). I'm using IntelliJ 2017.2.5
The modules that use a database did not get a JPA facet, and I don't recall it ever being offered by IntelliJ, so I had to add this manually. There is no persistence.xml since all of this is handled by Spring. In the Persistence tool window, it did pick up the Spring/Hibernate entityManagerFactory with all mapped classes.
So far, so good. I added a datasource, so there's a database connection, and the queries can be translated to SQL.
I had to add "name" attribute to all my @Column annotations because at first the generated SQL didn't match the database column names - despite that Hibernate managed fine without that. The documentation tells me that I can set a NamingStrategy on the SessionFactory in the Persistence tool windows - but I can't find that option. (There's an entityManagerFactory, not a SessionFactory. Perhaps that's why??).
OK so with that out of the way I can type a query in the JPA Console, code completion works. When there's no output of the query (because conditions don't match with the database), it all seems fine. But displaying output gives me the above exception.
I'd be happy then to test my query, and query performance, by generating SQL from the query and running that in an SQL buffer. However, trying to generate SQL from the query gives me another error:
> select s from Shift s where id = 1330
[2017-10-09 11:38:07] UnsupportedOperationException: org.hibernate.internal.SessionImpl is not supported
So I'm blocked on trying to use this tool and I'd appreciate any help. If I need to provide extra information, logs, etc, let me know...
--Tim
Please sign in to leave a comment.
Well it seemd that restarting the IDE fixed the issue with query output... Weird!??
Still cannot generate SQL from the JPA queries though, same error as posted above.
I'd still very much like to get that to work, so that I can ask the database to explain the query plan and check which indices are used.
The JPA persistence support for Java Config - only configuration is still not completely supported. Could be same cause as in https://youtrack.jetbrains.com/issue/IDEA-151230 Try 2017.3 from https://www.jetbrains.com/idea/nextversion/ Try also this workaround: https://youtrack.jetbrains.com/issue/IDEA-151230#comment=27-1640820
It would also be helpful to get a sample project to reproduce
Tried the latest EAP today but that made no difference. Still cannot generate SQL from my JPA-QL queries, and still cannot use the project where there's a class hierarchy with nested sub-classes, and one of relations joining only to a specific subclass of that hierarchy.
I'll make some time soon to create minimal-sample projects to demonstrate these issues; any problem if the sample projects will use Kotlin instead of Java?
>any problem if the sample projects will use Kotlin instead of Java?
The point is to create the project which would mimic the exact setup which does not work for you. Thank you.