使用postgresql时报的异常

发布于 2021-11-30 10:04:20 字数 781 浏览 901 评论 4

@Dreampie 你好,想跟你请教个问题:

在调用Account.dao.findAll()时报如下错误。

execute error. SELECT * FROM sso_user
org.postgresql.util.PSQLException: ERROR: syntax error at or near "RETURNING"

采用的驱动为

<dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>9.4-1202-jdbc4</version> </dependency>

Account类如下:

/**  * Created by loyin on 15/9/6.  */ @Table(name="sso_user") public class Account extends Model<Account> { public static Account dao=new Account();
}

换了好几个版本的驱动都是报同样的问题。请帮忙解决下。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

檐上三寸雪 2021-11-30 19:08:48

那你用github上最新代码   @Table(xxx,generatedKey="")如果没有自增并且是自己手动set值,把自增主键设置为空,其实@Table 里已经设计了 代码级的主键生成策略,你可以自实现  Generator,不用每次都自己手动set进去,@Table(xxx,generatedKey="id",generator=xx.class,generated=true)  使用generator来生成主键

多彩岁月 2021-11-30 18:48:06

@Dreampie 表没有自增主键。采用自定义的主键生成机制。

永不分离 2021-11-30 18:47:05

表有自增主键吗,用github上最新的代码试试,如果还有问题 @ 我

瑾夏年华 2021-11-30 18:40:08
Whe using PostgreSQL, all SELECT statements will fail with message: org.postgresql.util.PSQLException: ERROR: syntax error at or near "RETURNING"

Seems to be related to this issue

This has been fixed with version 1.1.2.

The fix requires the QuirkMode enum flag to be set to PostgreSQL when creating a new instance of sql2o. It changes default behaviour of queries to NOT fetch generated keys by default. When it is needed to fetch generated keys, the returnGeneratedKeys parameter in the generateQuery method should be set.

http://stackoverflow.com/questions/24636120/postgres-jdbc-driver-psqlexception-syntax-error-at-or-near-returning 看看是不是这个

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文