2
I’ve been working for 1 year with Grails and Intellij Community 14, and I’ve noticed some different behaviors between running the project through the command line and using IDEA’s Run 'Aplication.main()'.
Put this doubt to try to understand once and for all what the difference is. I will try to exemplify a situation that I have come across lately.
Think of two Entities. A "Service" and another "Status", as below:
class Servico {
static hasOne = [status: Status]
static constraints = {
status nullable: true
}
}
class Status {
String nome
static hasMany = [servicos: Servico]
static constraints = {
nome nullable: false, unique: true
}
}
The project works normally running on IDEA, but when using the command line run-app, the following error occurs when trying to save a "Service":
Object References an Unsaved Transient instance - save the Transient instance before Flushing: project. Status
Which doesn’t make much sense anymore, since the Status already exists at the base before the Service.
After that, when trying to run the project again in IDEA, another error occurs face to face:
org.springframework.Beans.factory.Beancreationexception: Error Creating bean with name 'grailsApplicationPostProcessor' defined in project. Application: Bean instantiation via Factory method failed; nested Exception is org.springframework.Beaninstantiationexception: Failed to instantiate [grails.boot.config.Grailsapplicationpostprocessor]: Factory method 'grailsApplicationPostProcessor' threw Exception; nested Exception is java.lang.Noclassdeffounderror: grails/Gorm/Entity
In order to be able to run again, I need to use a "grails clean". After this command (or delete the build folder) the project works properly again.
Apparently IDEA is generating a different build folder than the one generated by the run-app.
Does anyone have any light on that?