Slick / slick-pg-将OffsetDateTime插入为VARCHAR和String

时间:2019-12-15 06:52:06

标签: scala slick slick-3.0

我有以下模型:

final case class Wallet(
                           ...
                           pointExpiry: Option[OffsetDateTime],
                           spinExpiry: OffsetDateTime,
                           ...
                           id: Int = 0,
                       )

final class WalletTable(tag: Tag) extends Table[Wallet](tag, "wallet") {
    def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
    ...
    def pointExpiry = column[Option[OffsetDateTime]]("point_expiry")
    def spinExpiry = column[OffsetDateTime]("spin_expiry")
    ...
    def * = (..., pointExpiry, spinExpiry, ..., id).mapTo[Wallet]
}

我尝试INSERT,这是日志:

15 00:30:19 [DB-1] DEBUG slick.compiler.QueryCompiler - Source:
| Bind
|   from s2: TableExpansion
|     table s3: Table wallet
|     columns: TypeMapping
|       0: ProductNode
...
|         4: Path s3.point_expiry : Option[java.time.OffsetDateTime']
|         5: Path s3.spin_expiry : java.time.OffsetDateTime'
...
|         16: Path s3.id : Int'
|   select: Pure t4
|     value: Path s2.id : Int'
...
15 00:30:19 [DB-1] DEBUG slick.jdbc.JdbcBackend.statement - Preparing insert statement (returning: id): insert into "wallet" (...,"point_expiry","spin_expiry",...)  values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
15 00:30:19 [DB-1] DEBUG slick.jdbc.JdbcBackend.statement - Executing prepared update: HikariProxyPreparedStatement@2041279209 wrapping insert into "wallet" (...,"point_expiry","spin_expiry",...)  values (...,NULL,'2100-12-31T00:00+07:00',...)
RETURNING "id"
15 00:30:19 [DB-1] DEBUG slick.jdbc.JdbcBackend.parameter - /-----+-----+-----+---------+------------------------+-----+-----+---------+---------+-----+--------+---------+---------+---------------------------+---------------------------\
15 00:30:19 [DB-1] DEBUG slick.jdbc.JdbcBackend.parameter - | 1   | 2   | 3   | 4       | 5                      | 6   | 7   | 8       | 9       | 10  | 11     | 12      | 13      | 14                        | 15                        |
15 00:30:19 [DB-1] DEBUG slick.jdbc.JdbcBackend.parameter - | Int | Int | Int | VARCHAR | String                 | Int | Int | DECIMAL | DECIMAL | Int | String | Boolean | VARCHAR | String                    | String                    |
15 00:30:19 [DB-1] DEBUG slick.jdbc.JdbcBackend.parameter - |-----+-----+-----+---------+------------------------+-----+-----+---------+---------+-----+--------+---------+---------+---------------------------+---------------------------|
15 00:30:19 [DB-1] DEBUG slick.jdbc.JdbcBackend.parameter - | 1   | 1   | 1   | NULL    | 2100-12-31T00:00+07:00 | 100 | 100 | NULL    | NULL    | 0   | 111    | true    | NULL    | 2019-12-15T00:30:05.37... | 2019-12-15T00:30:05.37... |
15 00:30:19 [DB-1] DEBUG slick.jdbc.JdbcBackend.parameter - \-----+-----+-----+---------+------------------------+-----+-----+---------+---------+-----+--------+---------+---------+---------------------------+---------------------------/

我不了解的内容:如果我从日志中复制粘贴生成的INSERT语句并手动运行它,则数据将成功插入。

但是从Tomcat(我从那里调用它)中,它会引发错误:

15-Dec-2019 00:30:19.560 SEVERE [http-nio-8080-exec-1] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [jersey-servlet] in context with path [] threw exception [org.glassfish.jersey.server.ContainerException: org.postgresql.util.PSQLException: ERROR: column "point_expiry" is of type date but expression is of type character varying
  Hint: You will need to rewrite or cast the expression.
  Position: 225] with root cause
    org.postgresql.util.PSQLException: ERROR: column "point_expiry" is of type date but expression is of type character varying
  Hint: You will need to rewrite or cast the expression.
  Position: 225
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2505)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2241)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:310)
        at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:447)
        at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:368)
        at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:158)
        at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:124)
        at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
        at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
        at slick.jdbc.LoggingPreparedStatement.$anonfun$executeUpdate$5(LoggingStatement.scala:170)

我想念什么?

0 个答案:

没有答案