Saturday, 15 June 2013

java - Spring @Query annotation with enum parameter -


Is it possible to use ENUM parameters with @Ni annotation?

Here is the code I use to find the user role:

  role userRole = roleRepository.findByRole (roles.USER); If (userRole == faucet) {LOGGER.debug ("There was no role with role: {}", roles. User); }   

and prints it

  No role was found with role: ROLE_USER   

But if I I try to find all the roles I find:

 For  (role r: roleRepository.findAll ()) LOGGER.debug ("{}", r); Role @ 1 a7f 0 [role = 1, role = role_adman, version = 0] role @ 1efe9ee [role iid = 2, role = role_stoff, version = 0] role @ 17070 [role = 3, role = role_user, version = 0] Role @  

RoleRepository:

  

Public Interface RoleRepository JpaRepository Extensions & Lt; Role, Long & gt; {@Query ("R R role from R r where lower = ROH = lower (role)" public role searchBirol (@Param ("role" role role); role of public class {public enum roles (ADMIN ( "ROLE_ADMIN"),

role:

  @inti @Table (name = "role" STAFF ("ROLE_STAFF"), USER ("ROLE_USER" ), Guest ("ROLE_GUEST"); personal string role; personal roles (string role) {this.role = role;} public string getRole () {return role;} @ override public string to string () Private roll role (name = "role") @ column (name = "role") personal string role (name = "role"); @ id = generated value (strategy = generation type.INNTTI) @ column (name = "roll_id", updateable = false) Public version of Long Milloloid () {return role ID;} public string getRole () {return role;} Public long match version () {Return version;} @ Override public Tring Tustring () {new Riflekshntostringbilder (it) .toString (); }}   

I suggest the proper use of type "role" property to this form Change in:

  @ column (named = "role") @ Named (EnumType.STRING) Personal role role;   

This will automatically correct the query result.

No comments:

Post a Comment