Results 1 to 2 of 2

Thread: Why An Exception On accountRepository?

  1. #1

    Question Why An Exception On accountRepository?

    The following line is in the HomeController class of the showcase sample.
    Code:
    		model.addAttribute(accountRepository.findAccountByUsername(currentUser.getName()));
    I am wondering why I get an exception
    org.springframework.dao.EmptyResultDataAccessExcep tion: Incorrect result size: expected 1, actual 0
    org.springframework.dao.support.DataAccessUtils.re quiredSingleResult(DataAccessUtils.java:71)
    org.springframework.jdbc.core.JdbcTemplate.queryFo rObject(JdbcTemplate.java:735)
    org.springframework.social.showcase.account.JdbcAc countRepository.findAccountByUsername(JdbcAccountR epository.java:56)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:318)
    org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:196)
    $Proxy36.findAccountByUsername(Unknown Source)
    when I have
    Code:
            Account current = accountRepository.findAccountByUsername(currentUser.getName());
    [URL="http://vicina.info"] 新闻,社区新闻,分类广告

  2. #2
    Join Date
    Aug 2004
    Posts
    1,075

    Default

    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:

    Code:
    <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.
    Craig Walls
    Spring Social Project Lead

Posting Permissions

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