postgresql - 无法将列的 266 :class java. math.BigDecimal 转换为 Long

标签 postgresql scala heroku playframework anorm

我正在使用 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 风格吗?我该如何解决?

奇怪的是,我尝试执行的事务(插入一行)确实有效——该行已添加。那么异常从何而来呢?

整个项目is one github ,如果有人需要更多上下文。

更新:案例类:

import java.math.BigDecimal
import org.joda.time.DateTime

case class Peak(
  time: DateTime,
  price: BigDecimal
)

最佳答案

我在使用不同的数据库系统时遇到过类似的问题。因此,我建议您检查数据库版本、配置、表的 DDL 以及用于细微差别的确切 JDBC 驱动程序,这些细微差别使列在一种情况下显示为 BigDecimal,在另一种情况下显示为 Long。

您可能还想查看这张工单:http://play.lighthouseapp.com/projects/82401/tickets/243-weird-typedoesnotmatch-exception-in-rc-3-and-final

列的顺序和某些版本的游戏似乎存在问题。

关于postgresql - 无法将列的 266 :class java. math.BigDecimal 转换为 Long,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17100009/

相关文章:

docker - Jenkins CI 在 Heroku 上部署 docker 镜像

database - 尝试在我的环境中设置 Postgres,但似乎无法获得对 intidb 的权限

postgresql - 如果在 docker-compose 启动时不存在,则创建 postgres 数据库

scala - 如何使用 SpecWithJUnit 将测试标记为 pendingUntilFixed

scala - 如何根据模式动态生成数据集?

Scala Postfix 运算符警告与 Scaladoc 相矛盾

postgresql - 如何从 postgresql 中的表创建 hstore?

sql - PostgreSQL,使用 pg_restore 更新现有行

ruby-on-rails-3 - 使用 Rails 针对 Postgres Follower(数据库镜像)运行分析

heroku - 将 CORS 与 Rails 4 和 heroku 结合使用