Announcement Announcement Module
Collapse
No announcement yet.
InvalidDataAccessApiUsageException querying for a matching User Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:

    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
    It seems your "loginForm.getUserName()" return null.

    You cannot pass null parameter to method generated by springdata jpa

    Comment


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

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

      Comment

      Working...
      X