Spring Data 通过枚举类型进行查询

3
我遇到了这样的问题,不知道该如何解决。问题如下: 我有一个模型:
@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进行操作,没有任何问题。但是一旦我在存储库中调用next方法:
domain.Authority findByAuthority(enums.Authority authority);

我得到了下面的异常(错误):
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
1个回答

4
"

select top ? ... 绝对不是 MySQL 的有效查询语句。

请检查您的 Hibernate 配置中的SQL 方言设置

"

啊,是的,非常感谢!我的方言是HSQLDialect! - user1827052

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接