I'm trying to convert a domain class into JSON.
def converter = null
try{
converter = events as JSON
} catch(e) {
log.error "error during conversion to JSON"
log.error e
}
return converter.toString()
I always get this error:
org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Executing action [findEvents] of controller
[com.geoadapta.geodata.DataAccessJsonController] caused exception:
java.lang.StackOverflowError
at java.lang.Thread.run(Thread.java:619)
Caused by: org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.StackOverflowError
... 1 more
Caused by: java.lang.StackOverflowError
at org.codehaus.groovy.util.AbstractConcurrentMap.getOrPut(AbstractConcurrentMap.java:20)
at grails.converters.JSON.value(JSON.java:188)
at grails.converters.JSON.convertAnother(JSON.java:160)
at grails.converters.JSON.value(JSON.java:192)
// hundreds of times
at grails.converters.JSON.value(JSON.java:192)
at grails.converters.JSON.convertAnother(JSON.java:160)
at grails.converters.JSON.value(JSON.java:192)
at grails.converters.JSON.convertAnother(JSON.java:160)
at grails.converters.JSON.value(JSON.java:192)
at grails.converters.JSON.convertAnother(JSON.java:160)
at grails.converters.JSON.value(JSON.java:192)
at grails.converters.JSON.convertAnother(JSON.java:160)
at grails.converters.JSON.value(JSON.java:192)
at grails.converters.JSON.convertAnother(JSON.java:160)
at grails.converters.JSON.value(JSON.java:192)
2010-06-23 16:21:28,390 [http-8080-1] DEBUG [/GeoAdaptaApp].[grails] - Disabling the response for futher output
This is the domain class: http://www.copypastecode.com/31527
The only problem I can see is the 'context' reference. But even if I set to 'null', I still get the stack overflow.
My converter is not propagating circular references.
I'd like to debug it and find out which property is causing the problem, but no luck so far.
Any hints?
Cheers
Sorry, would prefer to add this as a comment, but do not have the rep to add comments yet.
In your domain class it sounds like there are several classes that extend off this one, how are you populating the 'events' object? Since you say the context is set to null and that is the only relationship that's defined directly, a list of unintended subclasses in your results is one way that springs to mind for how you could get into such a deep recursion scenario.
To work around the immediate problem so you can do some debugging, have you tried calling:
converter.setRenderDomainClassRelations(false)
Related
I have a legacy system that I am migrating to Grails 3 but I'm running into a naming convention issue. One of our tables is called Application but that is also the name of the Groovy class that runs the application. There seems to be an issue where GORM is confusing the 2 classes and giving type-casting errors. I have tried explicitly casting my Application class in my ApplicationDegree class to try and force GORM to recognize which class I am trying to use but no success.
I know an option is that I can rename my domain Application class to something else and manually map it to the appropriate database table but I want to avoid that as I foresee issues down the road.
So, other than renaming my Domain classes, how can I get Grails/GORM to make the correct mapping.
Grails 3.1.4
Code:
ApplicationDegree ad = ApplicationDegree.findById(10);
Class:
class ApplicationDegree {
Boolean isPrimary
domain.package.Application application
Degree degree
static hasMany = [applicationDegreeMajors: ApplicationDegreeMajor,
applicationDegreeMinors: ApplicationDegreeMinor]
static belongsTo = [domain.package.Application, Degree]
static mapping = {
version false
degree column: 'degree_code'
isPrimary column: 'isPrimary'
}
}
StackTrace:
ERROR org.grails.spring.beans.factory.OptimizedAutowireCapableBeanFactory - Bean couldn't be autowired using grails optimization: Property 'application' threw exception; nested exception is java.lang.IllegalArgumentException: argument type mismatch
ERROR org.grails.spring.beans.factory.OptimizedAutowireCapableBeanFactory - Retrying using spring autowire
ERROR org.grails.web.errors.GrailsExceptionResolver - IllegalStateException occurred when processing request: [GET] /app4grad_V2/college/applications/
Cannot convert value of type [app4grad.Application] to required type [domain.package.Application] for property 'application': no matching editors or conversion strategy found. Stacktrace follows:
java.lang.reflect.InvocationTargetException: null
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.hibernate.InstantiationException: Could not instantiate entity: : domain.package.ApplicationDegree
at app4grad.college.ApplicationsController$$EPuFyMDe.index(ApplicationsController.groovy:14)
... 3 common frames omitted
Caused by: java.lang.reflect.InvocationTargetException: null
... 4 common frames omitted
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [app4grad.Application] to required type [domain.package.Application] for property 'application'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [app4grad.Application] to required type [domain.package.Application] for property 'application': no matching editors or conversion strategy found
... 4 common frames omitted
Caused by: java.lang.IllegalStateException: Cannot convert value of type [app4grad.Application] to required type [domain.package.Application] for property 'application': no matching editors or conversion strategy found
... 4 common frames omitted
I had the same problem, the problem is that you're using a reserved name : https://grails.org/wiki/Reserved%20Names
Using Intelij Idea you can easily rename you're domain class and the IDE will do the rest for you.
When I run my Dataflow pipeline, I get the exception below complaining that my DoFn can't be serialized. How do I fix this?
Here's the stack trace:
Caused by: java.lang.IllegalArgumentException: unable to serialize contrail.dataflow.AvroMRTransforms$AvroReducerDoFn#bba0fc2
at com.google.cloud.dataflow.sdk.util.SerializableUtils.serializeToByteArray(SerializableUtils.java:51)
at com.google.cloud.dataflow.sdk.util.SerializableUtils.ensureSerializable(SerializableUtils.java:81)
at com.google.cloud.dataflow.sdk.runners.DirectPipelineRunner$Evaluator.ensureSerializable(DirectPipelineRunner.java:784)
at com.google.cloud.dataflow.sdk.transforms.ParDo.evaluateHelper(ParDo.java:1025)
at com.google.cloud.dataflow.sdk.transforms.ParDo.evaluateSingleHelper(ParDo.java:963)
at com.google.cloud.dataflow.sdk.transforms.ParDo.access$000(ParDo.java:441)
at com.google.cloud.dataflow.sdk.transforms.ParDo$1.evaluate(ParDo.java:951)
at com.google.cloud.dataflow.sdk.transforms.ParDo$1.evaluate(ParDo.java:946)
at com.google.cloud.dataflow.sdk.runners.DirectPipelineRunner$Evaluator.visitTransform(DirectPipelineRunner.java:611)
at com.google.cloud.dataflow.sdk.runners.TransformTreeNode.visit(TransformTreeNode.java:200)
at com.google.cloud.dataflow.sdk.runners.TransformTreeNode.visit(TransformTreeNode.java:196)
at com.google.cloud.dataflow.sdk.runners.TransformHierarchy.visit(TransformHierarchy.java:109)
at com.google.cloud.dataflow.sdk.Pipeline.traverseTopologically(Pipeline.java:204)
at com.google.cloud.dataflow.sdk.runners.DirectPipelineRunner$Evaluator.run(DirectPipelineRunner.java:584)
at com.google.cloud.dataflow.sdk.runners.DirectPipelineRunner.run(DirectPipelineRunner.java:328)
at com.google.cloud.dataflow.sdk.runners.DirectPipelineRunner.run(DirectPipelineRunner.java:70)
at com.google.cloud.dataflow.sdk.Pipeline.run(Pipeline.java:145)
at contrail.stages.DataflowStage.stageMain(DataflowStage.java:51)
at contrail.stages.NonMRStage.execute(NonMRStage.java:130)
at contrail.stages.NonMRStage.run(NonMRStage.java:157)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:65)
at contrail.stages.ValidateGraphDataflow.main(ValidateGraphDataflow.java:139)
... 6 more
Caused by: java.io.NotSerializableException: org.apache.hadoop.mapred.JobConf
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
at com.google.cloud.dataflow.sdk.util.SerializableUtils.serializeToByteArray(SerializableUtils.java:47)
... 27 more
To add to what Jeremy says...
Another common cause of Serializable issues is when you use an anonymous DoFn within a non-static context. Anonymous inner classes have an implicit pointer to the enclosing class, which will cause it to get serialized as well.
If you scroll through the stack trace, one of the causes clearly identifies the data that isn't serializable.
Caused by: java.io.NotSerializableException: org.apache.hadoop.mapred.JobConf
The problem was my DoFn was taking a JobConf instance in the constructor and storing it in an instance variable. I was assuming JobConf was serializable but it turns out it isn't.
To solve this I did the following
I marked the JobConf member variable as transient so that it wouldn't be serialized.
I created a separate variable of type byte[] to store a serialized version of JobConf
In my constructor I serialized JobConf to a byte[] and stored it in an instance variable.
I overrode startBundle and deserialized the JobConf from the byte[]
Here's a gist with my DoFn.
Given a Main UI which encapsulates a vaadin Navigator, i need to call it from a search view so as to display search results in another view:
1) Main Ui
Navigator nav = new Navigator(this, content)
nav.addView("/search", new SearchView())
...
So everything works fine (with other views), until i implement the search view:
private static final String VIEW_SEARCH= "search"
private static final String VIEW_RESULTS = "searchResults"
in the constructor:
public SearchView() {
UI.getCurrent().getNavigator().addView(VIEW_SEARCH, new SearchView())
UI.getCurrent().getNavigator().addView(VIEW_RESULTS, new SearchResultsView())
which renders a stack overflow error:
*********************************************************
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message transform method call failed at ../../../src/share/instrument/JPLISAgent.c line: 844
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message transform method call failed at ../../../src/share/instrument/JPLISAgent.c line: 844
2013-12-21 19:47:00,772 ERROR [DefaultErrorHandler] -
com.vaadin.server.ServerRpcManager$RpcInvocationException: Unable to invoke method click in com.vaadin.shared.ui.button.ButtonServerRpc
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:170)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:118)
at com.vaadin.server.communication.ServerRpcHandler.handleBurst(ServerRpcHandler.java:207)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:111)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:91)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1382)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238)
at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.java:53)
at grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter.doFilter(RequestHolderAuthenticationFilter.java:49)
at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.java:82)
at grails.plugin.springsecurity.web.filter.DebugFilter.invokeWithWrappedRequest(DebugFilter.java:102)
at grails.plugin.springsecurity.web.filter.DebugFilter.doFilter(DebugFilter.java:69)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.reflect.InvocationTargetException
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:168)
... 15 more
Caused by: com.vaadin.event.ListenerMethod$MethodException: Invocation of method buttonClick in com.webvibes.conquest.ui.KMUI$2 failed.
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:528)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:969)
at com.vaadin.ui.Button.fireClick(Button.java:368)
at com.vaadin.ui.Button$1.click(Button.java:57)
... 16 more
Caused by: java.lang.StackOverflowError
at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.webvibes.conquest.ui.SearchView.<init>(SearchView.groovy:43)
at com.webvibes.conquest.ui.SearchView.<init>(SearchView.groovy:43)
The goal here is pretty basic, the search view handles a Button which opens up a new view for the results with parameters:
KMUI.getCurrent().getNavigator().navigateTo(VIEW_RESULTS)
Thanks for any help.
* UPDATE:
Well, it seems that putting
UI.getCurrent().getNavigator().addView(VIEW_SEARCH, new SearchView())
UI.getCurrent().getNavigator().addView(VIEW_RESULTS, new SearchResultsView())
directly into the main UI does the job,
but, in that case i miss the results constructor to send the results... what is the best way to send results (HashMap) to the reults view:
No signature of method: com.vaadin.navigator.Navigator.navigateTo() is applicable for argument types: (java.lang.String, java.util.HashMap) values: [/searchResults, [total:0, hits:org.compass.core.impl.DefaultCompassDetachedHits#340f9d23, ...]]
Possible solutions: navigateTo(java.lang.String)
KMUI.getCurrent().getNavigator().navigateTo(VIEW_RESULTS, res)
You can use the session to pass parameter to another view.
Check this link for an example:
Setting and reading session attributes
I am trying to pull all the PostOrder's out where a child instance is present
My domain is as follows:
class PostOrder {
String pOrder
Date dateCreated
Picture picture
Post posts
Video video
static hasMany = [children : Child]
}
and the method i am trying to use to get the objects is:
def getAllInOrder(Child child){
def json = PostOrder.findAllByChildren(child, sort: 'dateCreated', order: 'desc') as JSON
return json
}
I am just getting sql exceptions from this.
Any Ideas?
also these are my exceptions:
util.JDBCExceptionReporter No value specified for parameter 1
errors.GrailsExceptionResolver SQLException occurred when processing request: [GET] /FYP/profile/appPosts - parameters:
child: 1
No value specified for parameter 1. Stacktrace follows:
java.sql.SQLException: No value specified for parameter 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2595)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2571)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2497)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2251)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
at org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2.doCall(GormStaticApi.groovy:105)
at com.fyp.timeline.ProfileController$$ENmIB8q0.getAllInOrder(ProfileController.groovy:636)
at com.fyp.timeline.ProfileController$$ENmIB8q0.appPosts(ProfileController.groovy:624)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Try
PostOrder.findAllByChildren(child, [sort: 'dateCreated', order: 'desc'])
Although I don't think this will fix your problem entirely because in this instance, child is expected to be a list. Try this:
PostOrder.all.findAll{it.children.contains(child)}
It seems like there should be a better way to do that, maybe someone else can ring in.
After upgrading to JSF2 (probably) one special accessor in an .xhtml file generates IllegalArgumentExceptions but I can't really find out why. Running the app on my local JBoss (4.2.2) does not generate this exception but this can be related to a difference between debug and live data.
Following stack trace is generated that I could extract from the production server log:
Caused by: javax.el.ELException: /xy/xy-subtemplate1.xhtml #131,45 value="#{someClass.someProperty}": java.lang.IllegalArgumentException
at com.sun.facelets.el.TagValueExpression.setValue(TagValueExpression.java:101)
at javax.faces.component.UIInput.updateModel(UIInput.java:818)
... 36 more
Caused by: java.lang.IllegalArgumentException
at sun.reflect.GeneratedMethodAccessor1134.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.el.BeanELResolver.setValue(BeanELResolver.java:108)
at com.sun.faces.el.DemuxCompositeELResolver._setValue(DemuxCompositeELResolver.java:255)
at com.sun.faces.el.DemuxCompositeELResolver.setValue(DemuxCompositeELResolver.java:281)
at org.apache.el.parser.AstValue.setValue(AstValue.java:114)
at org.apache.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:249)
at com.sun.facelets.el.TagValueExpression.setValue(TagValueExpression.java:93)
... 37 more
someClass is being iterated over in a list and has the following methods to access someProperty:
public int getSomeProperty() {
return this.getSomeRelatedEnum().ordinal();
}
public void setSomeProperty( final int index) {
this.setSomeRelatedEnum( SomeRelatedEnum.fromOrdinal( index) );
}
How can this lead to the IllegalArgumentException mentioned above?
That can happen when the setter method after all expects a different argument type than the one which is provided from EL on.
I guess that it's related to the fact that hardcoded/unconverted numbers in EL are by default treated as long and not as int. Try either changing the int to be long, or providing an explicit integer converter on the input component like so <h:someInput converter="javax.faces.Integer">.
By the way, why don't you just get/set the enum itself directly? Getting/setting the enum by its ordinal is whacky.