How to cope with 'org.postgresql.util.PSQLExce

2019-03-01 18:46发布

Upon registration to my Grails app, the user receives an email with a confirmation link. Clicking that link, takes her to the according 'enable' action.

This worked flawlessly. However, there now seems to be an error with a very specific token, which fails the user.save() of this snippet:

assert !user.isDirty()  // assertion is ok
user.enabled = true
user.confirmationToken = null
assert user.isDirty()   // assertion is ok

if (user.save()) {  // FAILS WITH ERROR BELOW
    // ...
}

Stacktrace:

[ 16.09.2011 11:57:47.591] [http-bio-localhost/127.0.0.1-8080-exec-3] 
ERROR 
org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver 
org.apache.commons.logging.impl.SLF4JLog 

 Exception occurred when processing request: [GET] /user/enable/bc73701c-d280-4de0-8951-7af9f2a3d636
Stacktrace follows:
org.postgresql.util.PSQLException: No value specified for parameter 1.
        at org.postgresql.core.v3.SimpleParameterList.checkAllParametersSet(SimpleParameterList.java:178)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:246)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:273)
        at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
        at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
        at myproj.UserService.enableUser(UserService.groovy:234)
        at myproj.UserController$_closure8.doCall(UserController.groovy:244)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
        at java.lang.Thread.run(Thread.java:619)

Note that I can create additional users in the same running instance - but the error (so far) only occurs with that code.

Any ideas on how to resolve that?

Versions in use:

  • PostgreSQL: 9.1beta3
  • JDBC-driver: postgresql:9.1-901.jdbc4
  • Grails: 2.0.0.BUILD-SNAPSHOT (Build #1378)

(Due to being on development builds for those parts, it might be a bug, but I am unsure about that.)

2条回答
祖国的老花朵
2楼-- · 2019-03-01 19:01

It does look like a bug. Somehow a parameter on the underlying SQL PreparedStatement didn't get set. Grails/GORM is supposed to do that. Are you able to run your app on a more stable version of Grails and/or the JDBC driver? It might help you troubleshoot and would give you the specifics to open a bug report.

EDIT: Another possibility just occurred to me. Perhaps you have a type mismatch somewhere, such as a String value that's trying to go into an INTEGER column? The driver might interpret "bad data" as "no data". Just a shot in the dark before you go too far down the other path.

查看更多
虎瘦雄心在
3楼-- · 2019-03-01 19:25

As outlined in the mentioned JIRA issue the problem stemmed from a unique-constraint which was set for a mapped class.

Moving the unique-contraint into the Mapping DC resolved the issue.

查看更多
登录 后发表回答