简体   繁体   English

Slick默默地保存失败,并且不会引发异常

[英]Slick silently fails to save and doesn't' throw an exception

I just ran into a very scary situation with slick. 我刚好碰到一个非常可怕的情况。 My table definition referred to a wrong column and I noticed that the inserts where not inserting yet there was no error/exception about the issue. 我的表定义引用了错误的列,我注意到在未插入的地方插入,但没有关于该问题的错误/异常。 It just "silently" failed. 它只是“无声地”失败了。

Is this normal slick behaviour? 这是正常的光滑行为吗?

So my table definition was like: 所以我的表定义就像:

  def expiredAt = column[Timestamp]["created_at"]
  def createdAt = column[Timestamp]["created_at"]

As you can see, the column referenced for both is the same column "created_at". 如您所见,两者引用的列都是同一列“ created_at”。 When I changed the expiredAt column to "expired_at" everything worked fine. 当我将expiredAt列更改为“ expired_at”时,一切正常。

But the really issue for me is that there was no exception thrown at all. 但是对我来说真正的问题是根本没有抛出异常。

Is this normal slick behaviour? 这是正常的光滑行为吗? What is going on under the covers? 幕后到底是怎么回事? Does it not return 0 for updatedRows? 它对updatedRows是否不返回0?

My save method looks like: 我的保存方法如下:

(users returning users.map(_.id)) += user 

I am using slick3. 我正在使用slick3。

Had the same problem, solved it with recover: 遇到相同的问题,并通过恢复解决了它:

val query = (users returning earningsForms.map(_.id) += user
db.run(query).recover{ ex: Throwable => Logger.error("Error occured when inserting user", ex)}

Don't know about Slick, but i've seen bonecp (default with play <2.4) swallow exceptions under certain conditions. 不了解Slick,但是我看到在某些情况下bonecp(默认播放<2.4)会吞下异常。

I had the same issue, wasted hours trying to find the problem. 我遇到了同样的问题,浪费了很多时间去寻找问题。 Stopped happening when I switched to HikariCP. 当我切换到HikariCP时停止发生。 Upgrade to play 2.4 if you can (uses hikaricp by default). 如果可以,请升级至播放2.4(默认情况下使用hikaricp)。 If you're stuck on 2.3, you'll have to use the hikaricp play plugin. 如果您坚持使用2.3,则必须使用hikaricp play插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM