我正在使用 Play 2.1.1、Postgress 和 Herkou,并且只从我的生产数据库中获得奇怪的异常。
在本地与 H2 相比,一切正常。然而,在生产中,相同的操作失败了:
2013-06-14T01:49:25.275717+00:00 app[web.1]: [←[37minfo←[0m] application - 2013-06-14T01:49:25.275Z - Updating cache with new peak 266
2013-06-14T01:49:48.310600+00:00 app[web.1]: [←[37minfo←[0m] application - Updating database with peak 266
2013-06-14T01:49:48.327490+00:00 app[web.1]: [←[31merror←[0m] application -
2013-06-14T01:49:48.327490+00:00 app[web.1]:
2013-06-14T01:49:48.327490+00:00 app[web.1]: ! @6eih9flgb - Internal server error, for (GET) [/updateDB] ->
2013-06-14T01:49:48.327490+00:00 app[web.1]:
2013-06-14T01:49:48.327490+00:00 app[web.1]: play.api.Application$$anon$1: Execution exception[[RuntimeException: TypeDoesNotMatch(Cannot convert 266:
class java.math.BigDecimal to Long for column ColumnName(peaks.price,Some(price)))]]
2013-06-14T01:49:48.327490+00:00 app[web.1]: at play.api.Application$class.handleError(Application.scala:289) ~[play_2.10-2.1.0.jar:2.1.0]
2013-06-14T01:49:48.327490+00:00 app[web.1]: at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10-2.1.0.jar:2.1.0]
2013-06-14T01:49:48.327490+00:00 app[web.1]: at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$12$$anonfun$apply$24.apply(PlayDefaultUp
streamHandler.scala:314) [play_2.10-2.1.0.jar:2.1.0]
2013-06-14T01:49:48.327490+00:00 app[web.1]: at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$12$$anonfun$apply$24.apply(PlayDefaultUp
streamHandler.scala:312) [play_2.10-2.1.0.jar:2.1.0]
2013-06-14T01:49:48.327490+00:00 app[web.1]: at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10-2.1.0.j
ar:2.1.0]
2013-06-14T01:49:48.327660+00:00 app[web.1]: at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10-2.1.0.j
ar:2.1.0]
2013-06-14T01:49:48.327660+00:00 app[web.1]: java.lang.RuntimeException: TypeDoesNotMatch(Cannot convert 266:class java.math.BigDecimal to Long for co
lumn ColumnName(peaks.price,Some(price)))
2013-06-14T01:49:48.322664+00:00 heroku[router]: at=info method=GET path=/updateDB host=www.bitcoinpeak.org fwd="84.94.173.221" dyno=web.1 connect=2ms
service=2019ms status=500 bytes=1941
2013-06-14T01:49:48.327660+00:00 app[web.1]: at scala.sys.package$.error(package.scala:27) ~[scala-library.jar:na]
2013-06-14T01:49:48.327660+00:00 app[web.1]: at anorm.Sql$.as(Anorm.scala:535) ~[anorm_2.10-2.1.0.jar:2.1.0]
2013-06-14T01:49:48.327660+00:00 app[web.1]: at anorm.Sql$class.executeInsert(Anorm.scala:474) ~[anorm_2.10-2.1.0.jar:2.1.0]
2013-06-14T01:49:48.327660+00:00 app[web.1]: at anorm.SimpleSql.executeInsert(Anorm.scala:370) ~[anorm_2.10-2.1.0.jar:2.1.0]
2013-06-14T01:49:48.327660+00:00 app[web.1]: at org.bitcoinpeak.Peak$$anonfun$addPeak$1.apply(Peak.scala:43) ~[bitcoin-peak_2.10-1.0-SNAPSHOT.jar:1
.0-SNAPSHOT]
2013-06-14T01:49:48.327660+00:00 app[web.1]: at org.bitcoinpeak.Peak$$anonfun$addPeak$1.apply(Peak.scala:40) ~[bitcoin-peak_2.10-1.0-SNAPSHOT.jar:1
.0-SNAPSHOT]
2013-06-14T01:50:24.933750+00:00 app[web.1]: [←[37minfo←[0m] application - 2013-06-14T01:50:24.933Z - Updating cache with new peak 266
2013-06-14T01:51:24.796588+00:00 app[web.1]: [←[37minfo←[0m] application - 2013-06-14T01:51:24.796Z - Updating cache with new peak 266
2013-06-14T01:51:40.719105+00:00 heroku[router]: at=info method=HEAD path=/ host=www.bitcoinpeak.org fwd="74.86.158.106" dyno=web.1 connect=1ms servic
e=7ms status=404 bytes=1900
2013-06-14T01:52:25.047381+00:00 app[web.1]: [←[37minfo←[0m] application - 2013-06-14T01:52:25.047Z - Updating cache with new peak 266
2013-06-14T01:52:33.646553+00:00 heroku[router]: at=info method=GET path=/ host=www.bitcoinpeak.org fwd="74.86.158.107" dyno=web.1 connect=2ms service
=21ms status=200 bytes=1892
2013-06-14T01:53:25.420489+00:00 app[web.1]: [←[37minfo←[0m] application - 2013-06-14T01:53:25.420Z - Updating cache with new peak 266
这是生产表的样子:
> \d+ Peaks
Table "public.peaks"
Column | Type | Modifiers | Storage | Stats target | Description
--------+-----------------------------+------------------------+---------+--------------+-------------
price | numeric(20,0) | not null | main | |
time | timestamp without time zone | not null default now() | plain | |
为什么在本地工作的相同代码在生产中失败?是 SQL 的味道吗?我该如何解决?
奇怪的是,我正在尝试执行的事务(插入一行)确实有效 - 添加了该行。那么异常从何而来?
如果有人需要更多上下文,整个项目就是一个 github 。
更新:案例类:
import java.math.BigDecimal
import org.joda.time.DateTime
case class Peak(
time: DateTime,
price: BigDecimal
)