Jul 28th, 2011, 10:23 AM
GORM domain from Java code.
I have something like this
1) Grails application --> Invokes message listener written in Java
2) Message Listener --> Reflectively invokes service classes written in Java
3) Now I want to create GORM Domain objects from these classes
For this I think I need to do two things (Correct me if I am wrong)
A) Get access to Grails applicationContext
B) Get the beans that I need e.g. domain objects and perform operations on them.
But before I do that can anyone help me how to do "A" ?
Jul 28th, 2011, 12:21 PM
So you want to instantiate the domain classes from your Java code? Do you then want to save them? What sort of operations? If you want access to the save() method and the validation errors, then I'm afraid you're best off waiting for Grails 2.0 which makes these things available to Java code.
Jul 28th, 2011, 02:27 PM
We have JMS Listeners (not using JMS plugin or spring JMSTemplate) that are loading service classes based on contents , so we are using class.forName to load service classes.
Originally Posted by pledbrook
What I want to do is load grails beans from these service classes. I am assuming that once I am able to load beans from service classes from grails context I will be back in dependency injected mechanism and everything will be using grails.
BTW When Grails 2.0 coming out ? Can I access it from any nightly releases?
Last edited by mahmood.khurram; Jul 28th, 2011 at 02:51 PM.
Jul 29th, 2011, 06:30 AM
I think I am able get my beans from servlets like this , If I warp this in singleton class then I am not reloading application context and I can call my groovy domain objects from my groovy beans.
GrailsApplication application = (GrailsApplication) getServletContext().getAttribute(GrailsApplication .APPLICATION_ID);