title: Authentication of users from two database tables in Spring Security
body: <p>I have two tables: User and Admin. Both of them I have a username, password and role. And I want to log in with either one form either for admin or user. I tried this:</p>
  
  <pre><code>@Autowired
      public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {
          auth.
                  jdbcAuthentication().dataSource(dataSource)
                  .usersByUsernameQuery("SELECT username,password FROM user WHERE username =?  UNION SELECT username,password FROM admin WHERE username =? ")
                  .authoritiesByUsernameQuery("SELECT username,role FROM user WHERE username =?  UNION SELECT username,role FROM admin WHERE username =? ");
      }
  </code></pre>
  
  <p>, but I got exception:</p>
  
  <pre><code>org.springframework.security.authentication.InternalAuthenticationServiceException: PreparedStatementCallback; bad SQL grammar [SELECT username,password FROM user WHERE username =?  UNION SELECT username,password FROM admin WHERE username =? ]; nested exception is java.sql.SQLException: No value specified for parameter 2
  </code></pre>
  
  <p>So how can I log in to system with authentication two object type (User, Admin)?</p>