Results 1 to 3 of 3

Thread: InvalidDataAccessApiUsageException querying for a matching User

  1. #1

    Default InvalidDataAccessApiUsageException querying for a matching User

    I have defined an interface for the User entity called UserRepository and it has defined one method that should allow it to find the matching user based upon the user_name:

    Code:
    public interface UserRepository
    extends JpaRepository<User, Integer>
    { 
        User findByUserName( String userName );
    }
    Then in my controller code I have the following usage:

    Code:
    @Controller
    @SessionAttributes
    public class LoginController
    {  
      @Autowired
      UserRepository userRepo;
      @RequestMapping( value  = "/loginForm", 
                       method = RequestMethod.POST )
      public String loginUser( @Valid LoginForm loginForm,
                               BindingResult result )
      {   
        User logUser = userRepo.findByUserName( loginForm.getUserName() );
        ...
      }
    }
    In the spring data jpa doc (http://static.springsource.org/sprin...ty-expressions) 1.3.2.2. Query creation it seems to indicate that this is what should be done. However when I run this at the login where the find would be executed I get:

    org.springframework.dao.InvalidDataAccessApiUsageE xception: The type [null] is not the expected [EntityType] for the key class [class com.diodesign.fitness.jpa.entities.User].; nested exception is java.lang.IllegalArgumentException: The type [null] is not the expected [EntityType] for the key class [class com.diodesign.fitness.jpa.entities.User].


    Any suggestions as to how to fix this?
    Thanks

  2. #2
    Join Date
    Apr 2011
    Posts
    107

    Default

    It seems your "loginForm.getUserName()" return null.

    You cannot pass null parameter to method generated by springdata jpa

  3. #3

    Default

    To test your thought I ran a print statement on loginForm.getUserName() just prior to the User logUser = userRepo.findByUserName( loginForm.getUserName() ); and it returns a string not a null.

    However, I determined the problem seems to be with the jpa entities themselves. I corrected them and it is now working.

    Thanks
    Last edited by sldahlin; Jun 10th, 2011 at 12:09 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •