google app engine - How do I access EntityManager from within Grails service (JPA + GAE) -
i'm having trouble accessing entitymanager within grails service:
my setup follows...
- basic grails application appengine , gorm-jpa plugins
- default settings pretty everything. haven't touched resources.groovy, persistence.xml etc.
some things good...
- i able access entitymanager within controllers adding "def entitymanager".
but...
- i have service i'm trying access entitymanager from, however, "java.lang.illegalstateexception: entitymanager closed!" exception.
is plugin closing entitymanager somewhere? need change scope of entitymanager somehow? there xml file need update ensure proper injection?
class googlecalendarservice implements initializingbean { void afterpropertiesset() { }
}def entitymanager public oauthtoken getaccesstoken(user u) { //can't access entitymanager here entitymanager.newquery(...) //throws illegalstateexception }
one weird note: reason, if re-save service while jetty , running service able access entitymanager once. if click reload (and have controller access service again) service can no longer access entitymanager...
i guess right way use entitymanagerfactory, this:
import org.springframework.orm.jpa.entitymanagerfactoryutils class googlecalendarservice implements initializingbean { void afterpropertiesset() { } def entitymanagerfactory entitymanager em public oauthtoken getaccesstoken(user u) { em = entitymanagerfactoryutils.gettransactionalentitymanager(entitymanagerfactory) //do stuff em } }
Comments
Post a Comment