Grails dynamic scaffolding error - java

I am new to Grails, I installed Grails 2.4 on Ubuntu 14.04
I have this Grails Domain:
class EndUser {
String username
String password
String fullName
String toString() {
"$fullName"
}
static hasMany = [projects: Project, tasks: Task]
static constraints = {
fullName()
username()
password()
}
}
and it's controller:
class EndUserController {
static scaffold = true
def index = {
// redirect(action: "list")
}
}
I am getting the error below, and everytime i create a new EndUser, I am getting an error page showing this message:
Error 500: Internal Server Error
URI
/ProjectTracker/endUser/create
Class
java.lang.NullPointerException
Message
null
What did I do wrong? and how can I fix it?
Please let me know if I need to provide more info.
|Running Grails application
|Server running. Browse to http://localhost:8080/ProjectTracker
| Error 2014-06-09 01:59:47,663 [http-bio-8080-exec-7] ERROR errors.GrailsExceptionResolver - NullPointerException occurred when processing request: [GET] /ProjectTracker/endUser/edit/1
Stacktrace follows:
Message: Error processing GroovyPageView: Error executing tag <g:form>: Error executing tag <g:render>: null
Line | Method
->> 527 | doFilter in /endUser/edit
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Caused by GrailsTagException: Error executing tag <g:form>: Error executing tag <g:render>: null
->> 38 | doCall in /endUser/edit
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Caused by GrailsTagException: Error executing tag <g:render>: null
->> 33 | doCall in /endUser/edit
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Caused by NullPointerException: null
->> 333 | hash in java.util.concurrent.ConcurrentHashMap
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 988 | get in ''
| 141 | getValue in grails.util.CacheEntry
| 81 | getValue in ''
| 33 | doCall . in endUser_edit$_run_closure2_closure27
| 38 | doCall in endUser_edit$_run_closure2
| 40 | run . . . in endUser_edit
| 189 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Thanks,
Khalil.

It looks like you hit this bug: https://jira.grails.org/browse/GRAILS-11430. It will be fixed in Grails 2.4.1; you can either wait until that version is released or try the workaround provided in the comments of that link, which has been reported to work.

Related

Hygieia JIRA Collector NullPointerException

I tried to include our JIRA to Hygieia Dashboard. But I always get a NPE in Jira-Collector.
This is the log-file:
hygieia-jira | 2016-05-10 08:27:06,304 ERROR c.c.d.c.s.FeatureDataClientSetupImpl - Unexpected error in Jira paging request of java.lang.NullPointerException
hygieia-jira | [null]
And the docker-compose settings:
hygieia-jira-feature-collector:
image: hygieia-jira-feature-collector:latest
container_name: hygieia-jira
volumes:
- ./logs:/hygieia/logs
links:
- mongodb:mongo
- hygieia-api
environment:
- JIRA_BASE_URL=https://our-jira.com/tracker/base64
- JIRA_CREDENTIALS=b2ZhMmFidDpibsdfGlkbWlsdfzYWfsfdub37527lpbmc=
- JIRA_ISSUE_TYPE_ID=267
- JIRA_SPRINT_DATA_FIELD_NAME=customfield_14290
- JIRA_EPIC_FIELD_NAME=customfield_15590

Unable to find ACL information for object identity 'org.springframework.security.acls.domain.ObjectIdentityImpl

NOTE: This question still has no correct answer!
I am running Grails 2.4.5 with Spring Security 2.0RC5 and ACL 2RC2. Sometimes I get the following error when I am loggedin with an ROLE_ADMIN and ROLE_USER account.
2015-08-28 16:05:17,994 [http-nio-8080-exec-7] ERROR [/majestella].[grails] - Servlet.service() for servlet grails threw exception
Message: Unable to find ACL information for object identity 'org.springframework.security.acls.domain.ObjectIdentityImpl[Type: majestella.Company; Identifier: 50e396b8eebefc5a84]'
Line | Method
->> 292 | readAclsById in grails.plugin.springsecurity.acl.AclService
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 38 | myhotels in majestella.admin.AdminHotelController
| 198 | doFilter . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 32 | doCall . . . . . in Users_mg_Documents_Grails_GGTS3_6_4_Server_majestella_grails_app_views_admin_index_gsp$_run_closure2
| 39 | run in Users_mg_Documents_Grails_GGTS3_6_4_Server_majestella_grails_app_views_admin_index_gsp
| 198 | doFilter . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 53 | doFilter . . . . in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
| 62 | doFilter in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
| 46 | doFilterInternal in org.grails.jaxrs.web.JaxrsFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Error |
2015-08-28 16:05:18,035 [http-nio-8080-exec-7] ERROR errors.GrailsExceptionResolver - NotFoundException occurred when processing request: [GET] /majestella/admin
Unable to find ACL information for object identity 'org.springframework.security.acls.domain.ObjectIdentityImpl[Type: majestella.Company; Identifier: 50e396b8eebefc5a84]'. Stacktrace follows:
Message: Error processing GroovyPageView: Error executing tag <g:include>: Unable to execute include: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Executing action [myhotels] of controller [majestella.admin.AdminHotelController] caused exception: Runtime error executing action
Line | Method
->> 527 | doFilter in /grails-app/views/admin/index.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Caused by GrailsTagException: Error executing tag <g:include>: Unable to execute include: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Executing action [myhotels] of controller [majestella.admin.AdminHotelController] caused exception: Runtime error executing action
->> 32 | doCall in /grails-app/views/admin/index.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Caused by ControllerExecutionException: Unable to execute include: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Executing action [myhotels] of controller [majestella.admin.AdminHotelController] caused exception: Runtime error executing action
->> 32 | doCall in Users_mg_Documents_Grails_GGTS3_6_4_Server_majestella_grails_app_views_admin_index_gsp$_run_closure2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 39 | run in Users_mg_Documents_Grails_GGTS3_6_4_Server_majestella_grails_app_views_admin_index_gsp
| 198 | doFilter . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 53 | doFilter . . . . in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
| 62 | doFilter in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
| 46 | doFilterInternal in org.grails.jaxrs.web.JaxrsFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Executing action [myhotels] of controller [majestella.admin.AdminHotelController] caused exception: Runtime error executing action
->> 116 | logThrowable in grails.plugin.cache.web.filter.AbstractFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 70 | doFilter in ''
| 32 | doCall . . . . . in Users_mg_Documents_Grails_GGTS3_6_4_Server_majestella_grails_app_views_admin_index_gsp$_run_closure2
| 39 | run in Users_mg_Documents_Grails_GGTS3_6_4_Server_majestella_grails_app_views_admin_index_gsp
| 198 | doFilter . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 53 | doFilter . . . . in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
| 62 | doFilter in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
| 46 | doFilterInternal in org.grails.jaxrs.web.JaxrsFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by ControllerExecutionException: Executing action [myhotels] of controller [majestella.admin.AdminHotelController] caused exception: Runtime error executing action
->> 198 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 32 | doCall . . . . . in Users_mg_Documents_Grails_GGTS3_6_4_Server_majestella_grails_app_views_admin_index_gsp$_run_closure2
| 39 | run in Users_mg_Documents_Grails_GGTS3_6_4_Server_majestella_grails_app_views_admin_index_gsp
| 198 | doFilter . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 53 | doFilter . . . . in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
| 62 | doFilter in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
| 46 | doFilterInternal in org.grails.jaxrs.web.JaxrsFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by ControllerExecutionException: Runtime error executing action
->> 198 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 32 | doCall . . . . . in Users_mg_Documents_Grails_GGTS3_6_4_Server_majestella_grails_app_views_admin_index_gsp$_run_closure2
| 39 | run in Users_mg_Documents_Grails_GGTS3_6_4_Server_majestella_grails_app_views_admin_index_gsp
| 198 | doFilter . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 53 | doFilter . . . . in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
| 62 | doFilter in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
| 46 | doFilterInternal in org.grails.jaxrs.web.JaxrsFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by InvocationTargetException: null
->> 198 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 32 | doCall . . . . . in Users_mg_Documents_Grails_GGTS3_6_4_Server_majestella_grails_app_views_admin_index_gsp$_run_closure2
| 39 | run in Users_mg_Documents_Grails_GGTS3_6_4_Server_majestella_grails_app_views_admin_index_gsp
| 198 | doFilter . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 53 | doFilter . . . . in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
| 62 | doFilter in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
| 46 | doFilterInternal in org.grails.jaxrs.web.JaxrsFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by NotFoundException: Unable to find ACL information for object identity 'org.springframework.security.acls.domain.ObjectIdentityImpl[Type: majestella.Company; Identifier: 50e396b8eebefc5a84]'
->> 292 | readAclsById in grails.plugin.springsecurity.acl.AclService
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 38 | myhotels in majestella.admin.AdminHotelController
| 198 | doFilter . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 32 | doCall . . . . . in Users_mg_Documents_Grails_GGTS3_6_4_Server_majestella_grails_app_views_admin_index_gsp$_run_closure2
| 39 | run in Users_mg_Documents_Grails_GGTS3_6_4_Server_majestella_grails_app_views_admin_index_gsp
| 198 | doFilter . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 53 | doFilter . . . . in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
| 62 | doFilter in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
| 46 | doFilterInternal in org.grails.jaxrs.web.JaxrsFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Using an account with ROLE_USER on the same page I do not get this error.
When I restart the server the error for the ROLE_ADMIN and ROLE_USER user is gone. There might be some caching problem or so.
How do I fix this error?
Edit: Here is the GSP I requested:
some html code
<g:include controller="adminUser" action="myUsers" />
My controller uses Spring Security Annotation:
#Secured(AccessRole.ROLE_USER)
class AdminController {
def index() {}
}
Edit: Here is the content of the GSP I include:
<%# page import="test.Hotel" %>
<g:each in="${hotels}" var="hotel">
<g:render template="hotel" model="[hotel: hotel]" />
</g:each>
I still need to see your GSP's at least, but I would bet your problem is related to the use of <g:include> and how you are using the SpringSecurity.
Could you try to remove the <g:include> tags from your pages and running your tests again?
The problem with that is that Spring Security is implemented with Servlet filters and you're including secured content after the check.
Possible workarounds:
Try to use Spring Security taglibs with your includes, or don't using
includes at all.
Another solution is to refactor your pages to load
your fragments with ajax.
For example, enclose your includes with spring security tags, to show only if the user has the correct roles:
<sec:ifAnyGranted roles="ROLE_USER">
<g:include controller="adminUser" action="myUsers" />
</sec:ifAnyGranted>
[]'s
Message: Unable to find ACL information for object identity 'org.springframework.security.acls.domain.ObjectIdentityImpl[Type: majestella.Company; Identifier: 50e396b8eebefc5a84]'
You haven't created the acl entries for majestella.Company with id 50e396b8eebefc5a84 in your database. Each records needs to have its permission registered on acl entries and related tables.
I still have no answer to this question but as a work around I deleted:
<g:include controller="adminUser" action="myUsers" />

DataSource.groovy not found. grails 2.4.4

I am getting this error while running the application. I am using postgres 9.4 database. I ensured that DataSource.groovy exists. I am on MAC OS X 10.10
grails> r-a
| Starting daemon...
| Compiling 450 source files
| Parent process shutdown. Exiting...
| Error Forked Grails VM exited with error
| Starting daemon.....
| Warning No config found for the application.
| Warning DataSource.groovy not found, assuming dataSource bean is configured by Spring
| Running Grails application
objc[2087]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
| Error 2015-04-10 12:24:40,201 [localhost-startStop-1] ERROR context.ContextLoader - Context initialization failed
Message: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsConfigurationException: Class not found loading Grails application: BootStrap
Line | Method
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by GrailsConfigurationException: Class not found loading Grails application: BootStrap
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by ClassNotFoundException: BootStrap
->> 366 | run in java.net.URLClassLoader$1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 355 | run in ''
| 354 | findClass in java.net.URLClassLoader
| 425 | loadClass in java.lang.ClassLoader
| 262 | run . . . in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
| Error 2015-04-10 12:24:40,261 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener - Error initializing the application: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsConfigurationException: Class not found loading Grails application: BootStrap
Message: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsConfigurationException: Class not found loading Grails application: BootStrap
Line | Method
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by GrailsConfigurationException: Class not found loading Grails application: BootStrap
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by ClassNotFoundException: BootStrap
->> 366 | run in java.net.URLClassLoader$1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 355 | run in ''
| 354 | findClass in java.net.URLClassLoader
| 425 | loadClass in java.lang.ClassLoader
| 262 | run . . . in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
| Error 2015-04-10 12:24:40,277 [localhost-startStop-1] ERROR core.StandardContext - Error listenerStart
| Error 2015-04-10 12:24:40,288 [localhost-startStop-1] ERROR core.StandardContext - Context [/yazh] startup failed due to previous errors
| Server running. Browse to http://localhost:8080/yazh
| Application loaded in interactive mode. Type 'stop-app' to shutdown.
| Enter a script name to run. Use TAB for completion:
| Parent process shutdown. Exiting...
| Error Forked Grails VM exited with error
This usually happens when there's an error in the Domain, Controller or Service classes. run with --stacktrace and you'll find the root cause
This isn't much of an answer, but I just experienced this error and was able to get rid of it with a grails clean and grails compile.

Grails, Jobs, Static Helper Methods and Hibernate Session

I have a Grails job-class (grails-app/jobs) who needs to call a static (helper) method (defined in src/groovy). This method calls get- and find-methods respectively on 2 different domain-objects. The result of the method call is returning a simple String (could return anything for that sake - doesn't matter).
My question is, how do I use .withTransaction or .withSession in the job-class when I'm calling a static method containing fetch of 2 (could be more) different domain-classes?
Or, how do I declare/use a Hibernate session in a job-class so that I don't have to use .withBlaBla?
EDIT (another EDIT at the bottom - sorry):
The lines where EZTable and EZRow is fetched is working. EmailReminder I had to wrap with EmailReminder.with... Now the lines with call to ServiceUtils.handleSubjectOrMessageString(ezTable, ezRow, emailReminder.subject) are causing an exception (this is added "now" - the entire job-class was working earlier with simple String-values).
class EmailReminderJob implements Job {
EmailReminder emailReminder
EZTable ezTable
EZRow ezRow
static triggers = {}
def void execute(JobExecutionContext context) {
List<String> emails = new ArrayList<String>(0)
ezTable = EZTable.get(new Long(context.mergedJobDataMap.get('ezTableId')))
ezRow = EZRow.get(new Long(context.mergedJobDataMap.get('ezRowId')))
EmailReminder.withTransaction { status ->
emailReminder = EmailReminder.get(new Long(context.mergedJobDataMap.get('emailReminderId')))
if(emailReminder.sendMessageToOwnerUser && emailReminder.ownerUser.email!=null)
emails.add(emailReminder.ownerUser.email)
if(emailReminder.sendMessageToOwnerCompany && emailReminder.ownerCompany.email!=null)
emails.add(emailReminder.ownerCompany.email)
if(emailReminder.emails!=null && emails.size()>0)
emails.addAll(new ArrayList<String>(emailReminder.emails))
if(emailReminder.messageReceiverUsers!=null && emailReminder.messageReceiverUsers.size()>0) {
for(user in emailReminder.messageReceiverUsers) {
if(user.email!=null)
emails.add(user.email)
}
}
}
if(emails.size()>0) {
String host = "localhost";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
Session session = Session.getDefaultInstance(properties);
try{
// Create a default MimeMessage object.
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(emailReminder.emailFrom));
for(email in emails) {
message.addRecipient(
Message.RecipientType.TO,
new InternetAddress(email)
);
}
message.setSubject(ServiceUtils.handleSubjectOrMessageString(ezTable, ezRow, emailReminder.subject));
message.setText(ServiceUtils.handleSubjectOrMessageString(ezTable, ezRow, emailReminder.definedMessage));
Transport.send(message);
}catch (MessagingException mex) {
mex.printStackTrace();
}
}
}
}
The static-method in my util-class under src/groove (the line EZColumn ezcolumn = EZColumn.get(id) and the next are causing the exception):
def static String handleSubjectOrMessageString(EZTable eztable, EZRow ezrow, String subjectOrMessage) {
String regex = '(?<=\\$\\$)(.*?)(?=\\$\\$)'
Pattern pattern = Pattern.compile(regex)
Matcher matcher = pattern.matcher(subjectOrMessage)
StringBuffer stringBuffer = new StringBuffer();
while(matcher.find()) {
if(subjectOrMessage.substring(matcher.start(), matcher.end()).contains('#')) {
String stringId = subjectOrMessage.substring(matcher.start(), matcher.end()).split('#')[0]
String name = subjectOrMessage.substring(matcher.start(), matcher.end()).split('#')[1]
try {
Long id = new Long(stringId)
EZColumn ezcolumn = EZColumn.get(id)
EZCell ezcell = EZCell.findByEzTableAndEzRowAndEzColumn(eztable, ezrow, ezcolumn)
matcher.appendReplacement(stringBuffer, fetchCellValues(ezcell, ezcolumn))
} catch(NumberFormatException nfe) {
if(stringId.equals("id")) {
if(name.equals("row"))
matcher.appendReplacement(stringBuffer, ezrow.id.toString())
else if(name.equals("table"))
matcher.appendReplacement(stringBuffer, eztable.id.toString())
else
matcher.appendReplacement(stringBuffer, "???")
}
}
}
}
matcher.appendTail(stringBuffer);
println stringBuffer.toString().replaceAll('\\$', "")
return stringBuffer.toString().replaceAll('\\$', "")
}
The exception:
| Error 2015-02-11 10:33:33,954 [quartzScheduler_Worker-1] ERROR core.JobRunShell - Job EmailReminderGroup.ER_3_EZTable_3 threw an unhandled Exception:
Message: null
Line | Method
->> 202 | run in org.quartz.core.JobRunShell
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
^ 573 | run in org.quartz.simpl.SimpleThreadPool$WorkerThread
| Error 2015-02-11 10:33:33,996 [quartzScheduler_Worker-1] ERROR core.ErrorLogger - Job (EmailReminderGroup.ER_3_EZTable_3 threw an exception.
Message: Job threw an unhandled exception.
Line | Method
->> 213 | run in org.quartz.core.JobRunShell
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
^ 573 | run in org.quartz.simpl.SimpleThreadPool$WorkerThread
Caused by NullPointerException: null
->> 202 | run in org.quartz.core.JobRunShell
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
^ 573 | run in org.quartz.simpl.SimpleThreadPool$WorkerThread
| Error 2015-02-11 10:33:34,005 [quartzScheduler_Worker-1] ERROR listeners.ExceptionPrinterJobListener - Exception occurred in job: null
Message: org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.NullPointerException]
Line | Method
->> 218 | run in org.quartz.core.JobRunShell
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
^ 573 | run in org.quartz.simpl.SimpleThreadPool$WorkerThread
Caused by SchedulerException: Job threw an unhandled exception.
->> 213 | run in org.quartz.core.JobRunShell
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
^ 573 | run in org.quartz.simpl.SimpleThreadPool$WorkerThread
Caused by NullPointerException: null
->> 202 | run in org.quartz.core.JobRunShell
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
^ 573 | run in org.quartz.simpl.SimpleThreadPool$WorkerThread
EDIT AGAIN :( :
I have many nested calls in my static method (fetchCellValues(ezcell, ezcolumn) in the matcher.appendReplacement(stringBuffer, fetchCellValues(ezcell, ezcolumn))-method is calling deeper to fetch values and I actually get a "no Session"-exception at one call (call regular as all the other calls trying to fetch another domain-object):
Message: org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: org.hibernate.LazyInitializationException: could not initialize proxy - no Session]
You use them like you would anywhere. Both are independent of the class they're called on; withTransaction just runs the wrapped code in a transaction, joining a current active transaction if there is one, and withSession makes the current Hibernate Session available to the wrapped code but otherwise doesn't do anything.
You don't indicate any reason for needing either, so it's not obvious what to advise specifically. You don't need a transaction if you're only reading data, and if you're calling domain class methods you shouldn't need access to the session.
One use for withTransaction that I've advocated in the past (pretty much the only use for it since it's typically misused) is to avoid lazy loading exceptions when there isn't an active session already. Wrapping code in a withTransaction block has the side effect of creating a session and keeping it open for the duration of the block and that lets you work with lazy-loaded instances and collections. Controllers have an active session because there's an open-session-in-view interceptor that starts a session at the beginning of the request, stores it in a ThreadLocal, and flushes and closes it at the end of the request. Jobs are similar because the plugin uses Quartz job start/end events to do the same thing.
But whether you are making your code transactional because of lazy loading or because you're updating, you should usually be doing the work in a transactional service.
Services are great for transactional work because they're transactional by default (only services that have no #Transactional annotations and include static transactional = false are non-transactional), and it's easy to configure transaction demarcation per-class and per-method with the #Transactional annotation. They are also great for encapsulating business logic, independent of how they're called; there's usually no need for a service method to have any HTTP/Job/etc. awareness, just pass it the data needed in String/number/boolean/object arguments and let it do its work.
I like to keep controllers simple, doing data binding from the request params and calling services to do the real work, then rendering a response or routing to the next page, and I do the same thing in Quartz jobs. Use Quartz for its scheduling functionality, but do the real work in a service. Dependency-inject the service like any bean (def fooService) and put all of the business logic and database work there. It keeps things cleanly delineated in the code, and makes testing easier since you can test the service methods without having to mock HTTP calls or Quartz.

Spring Data java.lang.NoSuchMethodError in grails

I am using mongo db plugin and spring-data-neo4j in my grails application.
I am using latest version of SDN and mongo db plugin.
Here is my buildconfig :
grails.servlet.version = "3.0" // Change depending on target container compliance (2.5 or 3.0)
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.work.dir = "target/work"
grails.project.target.level = 1.6
grails.project.source.level = 1.6
//grails.project.war.file = "target/${appName}-${appVersion}.war"
grails.server.port.http = 1111
grails.project.fork = [
// configure settings for compilation JVM, note that if you alter the Groovy version forked compilation is required
// compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
// configure settings for the test-app JVM, uses the daemon by default
test: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
// configure settings for the run-app JVM
run: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
// configure settings for the run-war JVM
war: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
// configure settings for the Console UI JVM
console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
]
grails.project.dependency.resolver = "maven" // or ivy
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// specify dependency exclusions here; for example, uncomment this to disable ehcache:
// excludes 'ehcache'
}
log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve
legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility
repositories {
inherits true // Whether to inherit repository definitions from plugins
grailsPlugins()
grailsHome()
mavenLocal()
grailsCentral()
mavenCentral()
// uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories
//mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
//mavenRepo "http://repository.jboss.com/maven2/"
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
// runtime 'mysql:mysql-connector-java:5.1.29'
// runtime 'org.postgresql:postgresql:9.3-1101-jdbc41'
test "org.grails:grails-datastore-test-support:1.0-grails-2.4"
compile 'org.springframework.data:spring-data-neo4j-rest:3.2.0.RELEASE'
}
plugins {
// plugins for the build system only
build ":tomcat:7.0.55"
// plugins for the compile step
compile ":scaffolding:2.1.2"
compile ':cache:1.1.7'
compile ":asset-pipeline:1.9.6"
// plugins needed at runtime but not for compilation
runtime ":hibernate4:4.3.5.5" // or ":hibernate:3.6.10.17"
runtime ":database-migration:1.4.0"
runtime ":jquery:1.11.1"
compile ":mongodb:3.0.2"
// Uncomment these to enable additional asset-pipeline capabilities
//compile ":sass-asset-pipeline:1.9.0"
//compile ":less-asset-pipeline:1.10.0"
//compile ":coffee-asset-pipeline:1.8.0"
//compile ":handlebars-asset-pipeline:1.3.0.3"
}
}
With this configuration i am getting following error :
Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'mongoTransactionManager' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTransactionManager': Cannot resolve reference to bean 'mongoDatastore' while setting bean property 'datastore'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDatastore': FactoryBean threw exception on object creation; nested exception is java.lang.NoSuchMethodError: org.springframework.data.util.ClassTypeInformation.from(Ljava/lang/Class;)Lorg/springframework/data/util/TypeInformation;
Line | Method
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1146 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 701 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'mongoTransactionManager' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTransactionManager': Cannot resolve reference to bean 'mongoDatastore' while setting bean property 'datastore'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDatastore': FactoryBean threw exception on object creation; nested exception is java.lang.NoSuchMethodError: org.springframework.data.util.ClassTypeInformation.from(Ljava/lang/Class;)Lorg/springframework/data/util/TypeInformation;
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1146 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 701 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'mongoTransactionManager': Cannot resolve reference to bean 'mongoDatastore' while setting bean property 'datastore'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDatastore': FactoryBean threw exception on object creation; nested exception is java.lang.NoSuchMethodError: org.springframework.data.util.ClassTypeInformation.from(Ljava/lang/Class;)Lorg/springframework/data/util/TypeInformation;
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1146 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 701 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'mongoDatastore': FactoryBean threw exception on object creation; nested exception is java.lang.NoSuchMethodError: org.springframework.data.util.ClassTypeInformation.from(Ljava/lang/Class;)Lorg/springframework/data/util/TypeInformation;
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1146 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 701 | run . . . in java.lang.Thread
Caused by NoSuchMethodError: org.springframework.data.util.ClassTypeInformation.from(Ljava/lang/Class;)Lorg/springframework/data/util/TypeInformation;
->> 255 | createMongoTemplate in org.grails.datastore.mapping.mongo.MongoDatastore
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 221 | afterPropertiesSet in ''
| 54 | getObject in org.grails.datastore.gorm.mongo.bean.factory.MongoDatastoreFactoryBean
| 334 | innerRun in java.util.concurrent.FutureTask$Sync
| 166 | run . . . in java.util.concurrent.FutureTask
| 1146 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 701 | run in java.lang.Thread
I am using grails 2.4.3 and groovy 2.3.

Categories