Announcement Announcement Module
No announcement yet.
Why An Exception On accountRepository? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why An Exception On accountRepository?

    The following line is in the HomeController class of the showcase sample.
    I am wondering why I get an exception
    org.springframework.dao.EmptyResultDataAccessExcep tion: Incorrect result size: expected 1, actual 0 quiredSingleResult(
    org.springframework.jdbc.core.JdbcTemplate.queryFo rObject( countRepository.findAccountByUsername(JdbcAccountR
    sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    java.lang.reflect.Method.invoke( npointUsingReflection(
    org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(
    $Proxy36.findAccountByUsername(Unknown Source)
    when I have
            Account current = accountRepository.findAccountByUsername(currentUser.getName());

  • #2
    It's had to say exactly why you get that exception, but I have a solid guess. Here are a few clues based on what does work in the showcase.

    Note that the Spring Social Showcase uses Spring Security for user authentication and authorization. Also note that in security.xml, all pages in the application require that the user be authenticated:

    <intercept-url pattern="/**" access="isAuthenticated()"  />
    Therefore, there's no way you can arrive at the home page without first having signed in. Attempts to go to the homepage unauthenticated will result in a redirect to the sign in page. So, by the time the user actually hits HomeController, they've already signed in and the Principal object is already populated, ready to fetch the account for the current user.

    If your app isn't using Spring Security or if your app is allowing access to that line of code you show without authentication, then you'll likely get the exception you got.