gpt4 book ai didi

jpa - Spring Data 通过枚举查找

转载 作者:行者123 更新时间:2023-12-04 02:52:04 25 4
gpt4 key购买 nike

我遇到了这样的问题,不知道如何解决。接下来是问题:我有下一个模型:

@Entity(name="Authority")
@Table(name="AUTHORITIES")
public class Authority implements GrantedAuthority {

@Id
private long id;

@Enumerated(EnumType.STRING)
@Column(name="authority")
private asdevelopment.action.enums.Authority authority;

/**
*
*/
private static final long serialVersionUID = 1L;

@Override
public String getAuthority() {
return authority.toString();
}

/**
* @return the id
*/
public long getId() {
return id;
}

}


public enum Authority {

CLIENT_ROLE, ADMIN_ROLE;

}

我可以保存权限并通过ID获取,没有任何问题。但是当我调用存储库中的下一个方法时:

domain.Authority findByAuthority(enums.Authority authority);

我得到下一个异常(exception):

Hibernate: select top ? authority0_.id as id1_, authority0_.authority as authority1_ from AUTHORITIES authority0_ where authority0_.authority=?
13:48:01.125 WARN [main] org.hibernate.engine.jdbc.spi.SqlExceptionHelper:143 - SQL Error: 1064, SQLState: 42000
13:48:01.125 ERROR [main] org.hibernate.engine.jdbc.spi.SqlExceptionHelper:144 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '2 authority0_.id as id1_, authority0_.authority as authority1_ from AUTHORITIES ' at line 1

最佳答案

选择顶部? ... 肯定不是 MySQL 的有效查询。

检查 SQL dialect setting在你的 Hibernate 配置中。

关于jpa - Spring Data 通过枚举查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17491441/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com