apache / apache/grails-intellij-plugin
Groovy/Grail Console cannot execute Database Scripts
- Dominant language
- Java
- Stars
- 17
- Forks
- 4
- Avg merge
- 5d 15h
- Merged PRs (30d)
- 4
Description
Groovy/Grail Console provided by IntelliJ IDEA cannot execute database scripts. Groovy comes with a default console, which can be used for executing groovy scripts. IntelliJ also provides a more advanced Console with code completion features. Let's say, I have a Person domain.
**Code**
```
package com.clinton
class Person {
String name
}
```
And Here is my test suite:
**Code**
```
import com.clinton.Person
def p = new Person(name: 'Fred').save()
println(Person.count)
```
1.First output, is from default groovy console. The Default Console can be started by typing grails console. Its ouptu after running the command is shown in attachment 1. It works according to the Output.
2. Same code is executed for Console provided by IntelliJ IDEA. It can be started by Tools>Groovy Console. And it throws an exception. Output of log is below:
import com.clinton.Person
def p = new Person(name: 'Fred').save()
println(Person.count)
Result: java.lang.IllegalStateException: Either class [com.clinton.Person] is not a domain class or GORM has not been initialized correctly or has already been shutdown. If you are unit testing your entities using the mocking APIs
**at** org.grails.datastore.gorm.GormEnhancer.stateException(GormEnhancer.groovy:161)
```
at org.grails.datastore.gorm.GormEnhancer.findInstanceApi(GormEnhancer.groovy:167)
at org.grails.datastore.gorm.GormEnhancer.findInstanceApi(GormEnhancer.groovy)
at org.grails.datastore.gorm.GormEntity$Trait$Helper.currentGormInstanceApi(GormEntity.groovy:1322)
at org.grails.datastore.gorm.GormEntity$Trait$Helper.save(GormEntity.groovy:98)
at org.grails.datastore.gorm.GormEntity$Trait$Helper$save.call(Unknown Source)
at com.clinton.Person.save(Person.groovy)
at com.clinton.Person.save(Person.groovy)
at org.grails.datastore.gorm.GormEntity$save.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at ideaGroovyConsole.run(ideaGroovyConsole.groovy:4)
at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)
at groovy.lang.GroovyShell.run(GroovyShell.java:518)
at groovy.lang.GroovyShell.run(GroovyShell.java:497)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:169)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at console.run(console.txt:25)
at groovy.ui.GroovyMain.processReader(GroovyMain.java:632)
at groovy.ui.GroovyMain.processFiles(GroovyMain.java:540)
at groovy.ui.GroovyMain.run(GroovyMain.java:382)
at groovy.ui.GroovyMain.process(GroovyMain.java:370)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:129)
at groovy.ui.GroovyMain.main(GroovyMain.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:49)
```
3. However, the IntelliJ Console is able to execute scripts which do not involve database interactions. Example:
```
> print "hi"
Result: hi
```
I will love to use the IntelliJ Console, because of the advance features it offers over the default Console provided by Groovy. Please check and fix this problem.
Thank you.
---
*Imported from [IDEA-158726](https://youtrack.jetbrains.com/issue/IDEA-158726) · Type: Bug · Votes: 3*
*Comments, attachments, dates and reporter are not part of the export — follow the link above for the full history.*
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the IntelliJ IDEA Groovy Console execution path and compare it with the Grails console, using the reported GormEnhancer stack trace to trace where GORM initialization differs. Reproduce the Person.save() and Person.count example; done means database-backed scripts run in the IntelliJ console while simple scripts continue to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- databases, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100