Announcement Announcement Module
No announcement yet.
InvalidDataAccessApiUsageException querying for a matching User Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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:

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

    public class LoginController
      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 ( 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].; nested exception is java.lang.IllegalArgumentException: The type [null] is not the expected [EntityType] for the key class [class].

    Any suggestions as to how to fix this?

  • #2
    It seems your "loginForm.getUserName()" return null.

    You cannot pass null parameter to method generated by springdata jpa


    • #3
      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.

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