IllegalStateException with naming parameters in tomcat

13,017

What fixed it is changing the '?' to :param and adding @Param("param") before the parameter in the method.

Meaning that the select method:

@Query(value = "SELECT * FROM agents limit ?1, ?2", nativeQuery = true)
public List<AgentEntity> getAll(int start, int length);

has changed to

@Query(value = "SELECT * FROM agents limit :start, :length", nativeQuery = true)
public List<AgentEntity> getAll(@Param("start") int start, @Param("length") int length);

That fixed the problem.

Share:
13,017
Ran
Author by

Ran

A Java and Android programmer

Updated on July 14, 2022

Comments

  • Ran
    Ran almost 2 years

    I've been using tomcat and spring for a long time (more than a year). Everything worked out great. Today, all of a sudden I get a weird error when starting tomcat:

    Caused by: java.lang.IllegalStateException: Using named parameters for method public abstract java.util.List com.securegion.monitorcenter.dao.IncidentsViewRepository.getFixedIncidents(java.lang.String,java.util.List,java.lang.String,java.lang.String,int,int) but parameter 'text' not found in annotated query 'select * from siemincidents where fixed = 1 and descriptioninfo like %?1% and incidentseverity in ?2 and starttimestamp >= ?3 and endtimestamp <= ?4 order by starttimestamp desc limit ?5, ?6'!

    I didn't knew what to do, but no one used the method so I deleted it. Then I restarted tomcat, and got

    Using named parameters for method public abstract java.util.List com.securegion.monitorce nter.dao.IncidentsViewRepository.getFixedIncidents(int,int) but parameter 'start' not found in annotated query 'select * from siemincidents where fixed = 1 order by starttimestamp desc limit ?1, ?2'!

    Again I didn't know what is this, so I deleted the tomcat server entirely from eclipse and created it again. This worked for half an hour, and then I got the same problem! Than, deleting tomcat doesn't help. What is weird is the the service in the DAO starts with "get" and not "find". I thought that maybe tomcat is confused, so I changed "get" to "fetch". Didn't help. I read here that instead of writing "?1" I should write ":text". But understand that writing with "?" worked for over a year, so I have MANY parameters with "?" - too much work for an annoying bug (it worked for over a year). I've checked all my files, and nothing important is changed today, so I don't know what file caused it.

    At the begging it only happened to me, but now it happens to a colleague. We use JENKINS to deploy our server, and JENKINS crashes in

    ERROR: Build step failed with exception
    org.codehaus.cargo.container.ContainerException: Failed to deploy [/etc/jenkins/jobs/mcg_DeployToDev/workspace/mcg/target/mcg.war]
        at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:107)
        at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:185)
        at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:73)
        at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:116)
        at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:103)
        at hudson.FilePath.act(FilePath.java:989)
        at hudson.FilePath.act(FilePath.java:967)
        at hudson.plugins.deploy.CargoContainerAdapter.redeploy(CargoContainerAdapter.java:103)
        at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:61)
        at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45)
        at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:761)
        at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:721)
        at hudson.model.Build$BuildExecution.post2(Build.java:183)
        at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:670)
        at hudson.model.Run.execute(Run.java:1766)
        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
        at hudson.model.ResourceController.execute(ResourceController.java:98)
        at hudson.model.Executor.run(Executor.java:374)
    Caused by: org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: FAIL - Deployed application at context path /mcg but context failed to start
    
        at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:566)
        at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deployImpl(TomcatManager.java:611)
        at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deploy(TomcatManager.java:291)
        at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:102)
        ... 17 more
    org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: FAIL - Deployed application at context path /mcg but context failed to start
    
        at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:566)
        at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deployImpl(TomcatManager.java:611)
        at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deploy(TomcatManager.java:291)
        at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:102)
        at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:185)
        at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:73)
        at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:116)
        at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:103)
        at hudson.FilePath.act(FilePath.java:989)
        at hudson.FilePath.act(FilePath.java:967)
        at hudson.plugins.deploy.CargoContainerAdapter.redeploy(CargoContainerAdapter.java:103)
        at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:61)
        at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45)
        at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:761)
        at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:721)
        at hudson.model.Build$BuildExecution.post2(Build.java:183)
        at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:670)
        at hudson.model.Run.execute(Run.java:1766)
        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
        at hudson.model.ResourceController.execute(ResourceController.java:98)
        at hudson.model.Executor.run(Executor.java:374)
    Build step 'Deploy war/ear to a container' marked build as failure
    Finished: FAILURE
    

    If it matters, I'm using tomcat 8.

    What can I do? It is such a huge problem that perhaps I'm just missing a minor glitch... What is it?