2013-07-05 56 views
3

我遇到了这样的问题,不知道如何解决它。问题是下一个: 我有一个型号:Spring Data findBy枚举

@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保存权威并获得没有任何问题。但随着SOOS我调用库下一个方法:

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 

回答

4

select top ? ...当然不是MySQL的有效查询。

检查您的Hibernate配置中的SQL dialect setting

+0

啊是的,非常感谢!我有HSQLDialect作为方言! – user1827052