Using 'Super' keyword in Grails Service Class causes infinite loop

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Using 'Super' keyword in Grails Service Class causes infinite loop

harshin
Hi,

I have written the grails service classes as shown below:

Class AService{

    def test(Map params){

        println "Parent : "+params
    }
}

Class BService extends AService{

    def test(Map params){
       
        println "Child : "+params
        super.test([c:1,d:2])
    }
}

And I have controller like this


Class TestController{
 
   def bService
   
  def index(){
 
       bService.test([a:1,b:2])
  }
 
}

The bService.test([a:1,b:2]) method is called in the TestControllers index action,the bService 'test' method has a 'super' keyword that should call the parent class[AService] 'test' method,but that is not happening insted it is calling the child class[BService] 'test' method itself and my code is going to infine loop.

Can anyone please help me on why the super.test([c:1,d:2]) is not calling the parent class[AService] 'test' method?
Reply | Threaded
Open this post in threaded view
|

Re: Using 'Super' keyword in Grails Service Class causes infinite loop

burtbeckwith
What version of Grails? This works for me in a 2.0.4 app.

Burt

harshin wrote
Hi,

I have written the grails service classes as shown below:

Class AService{

    def test(Map params){

        println "Parent : "+params
    }
}

Class BService extends AService{

    def test(Map params){
       
        println "Child : "+params
        super.test([c:1,d:2])
    }
}

And I have controller like this


Class TestController{
 
   def bService
   
  def index(){
 
       bService.test([a:1,b:2])
  }
 
}

The bService.test([a:1,b:2]) method is called in the TestControllers index action,the bService 'test' method has a 'super' keyword that should call the parent class[AService] 'test' method,but that is not happening insted it is calling the child class[BService] 'test' method itself and my code is going to infine loop.

Can anyone please help me on why the super.test([c:1,d:2]) is not calling the parent class[AService] 'test' method?
Reply | Threaded
Open this post in threaded view
|

Re: Using 'Super' keyword in Grails Service Class causes infinite loop

harshin
Hi,

I am using grails 2.1.1
Reply | Threaded
Open this post in threaded view
|

Re: Using 'Super' keyword in Grails Service Class causes infinite loop

bksaville
You may want to check your file names.  I've seen some really odd behavior (including infinite loops) when file names do not match the class names exactly, including capitalization.  Just an idea.

-Brian


On Thu, Apr 18, 2013 at 1:06 AM, harshin <[hidden email]> wrote:
Hi,

I am using grails 2.1.1



--
View this message in context: http://grails.1312388.n4.nabble.com/Using-Super-keyword-in-Grails-Service-Class-causes-infinite-loop-tp4643689p4643738.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Using 'Super' keyword in Grails Service Class causes infinite loop

dlee
In reply to this post by harshin
harshin, did you find anything out about this? I am having the same issue.
Reply | Threaded
Open this post in threaded view
|

Re: Using 'Super' keyword in Grails Service Class causes infinite loop

harshin
Hi,

No i haven't found any solution.I have changed my code , so that i don't have to use the 'super' key word.
Reply | Threaded
Open this post in threaded view
|

Re: Using 'Super' keyword in Grails Service Class causes infinite loop

gafilson
I'm also seeing this issue, but only upon upgrading from grails 2.3.3 to grails 2.4.3.
Reply | Threaded
Open this post in threaded view
|

Re: Using 'Super' keyword in Grails Service Class causes infinite loop

gafilson
For what it's worth, I was running this in a controller, and the thing that fixed it for me was to remove annotation based transactionality and use programmatic transactionality instead.  Instead of:

@Transactional
class FooController extends BarController {

  def fooAction() {
    return super.fooAction()
  }

}

I had to do:

class FooController extends BarController {

  def fooAction() {
    def results
    FooDomain.withTransaction {
      results = super.fooAction()
    }
    return results
  }

}

Most likely this is because Grails has some fanciness w/r to controller/action pairs where it doesn't really make sense for actions to be called in a hierarchical fashion.   Rather there should be a service method somewhere that would be called by the super action or the sub action.