Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data findBy Enum

i met such problem and don't know how to resolve it. Problem is next: I have next model:

@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;

}

i can save authority and get by ID without any problems. But as soos as i call next method in repository:

domain.Authority findByAuthority(enums.Authority authority);

i get next exceptions:

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
like image 648
user1827052 Avatar asked Dec 03 '25 06:12

user1827052


1 Answers

select top ? ... is certainly not a valid query for MySQL.

Check SQL dialect setting in your Hibernate configuration.

like image 146
axtavt Avatar answered Dec 06 '25 10:12

axtavt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!