How to fix HSQL DataSource + TxM where identity always return 0

谁都会走 提交于 2019-12-10 10:59:55

问题


I am using Hibernate to do my ORM stuff w/ HSQL for tests. It seems that a connection is fetched to do the insert and then returned. Straight after that HIbernate gets a connection then tries to fetch the identity from HSQL but that returns 0 which is obviously wrong.

WHen i was running w/out a tm and datasource using a plain pooled connection everything worked but with the new tm + ds i am getting this problem.


回答1:


The answer is the DataSource should be tx aware, so that connections are sticky for each new tx. The original problem was a different connection was used to fetch the identity of the new row which of course resulted in 0 being returned. If the connection remained sticky for the initial insert and call identity then everything works.



来源:https://stackoverflow.com/questions/4857730/how-to-fix-hsql-datasource-txm-where-identity-always-return-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!