title: could not extract ResultSet in Hibernate application
body: <p>I have problem trying authenticate user using spring security and extracting users from the db. I am using Postgres for this purpose and I am sure it is configured because I am able to manipulate entities from other tables. Here is the error I receive:</p>
  
  <pre><code>    org.springframework.security.authentication.InternalAuthenticationServiceException: could not extract ResultSet
      at org.springframework.security.authentication.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:125)
      at org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:143)
      at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:167)
      at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:192)
      at org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter.attemptAuthentication(UsernamePasswordAuthenticationFilter.java:93)
      at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:217)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:120)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:120)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:91)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:53)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:213)
      at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176)
      at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
      at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
      at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123)
      at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
      at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:91)
      at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.getResultSet(AbstractLoadPlanBasedLoader.java:449)
      at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeQueryStatement(AbstractLoadPlanBasedLoader.java:202)
      at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:137)
      at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:102)
      at org.hibernate.loader.collection.plan.AbstractLoadPlanBasedCollectionInitializer.initialize(AbstractLoadPlanBasedCollectionInitializer.java:100)
      at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:693)
      at org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:92)
      at org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1897)
      at org.hibernate.collection.internal.AbstractPersistentCollection$4.doWork(AbstractPersistentCollection.java:558)
      at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:260)
      at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:554)
      at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:142)
      at org.hibernate.collection.internal.PersistentSet.iterator(PersistentSet.java:180)
      at com.musala.ving.serviceimpl.MyUserDetailsService.buildUserAuthority(MyUserDetailsService.java:49)
      at com.musala.ving.serviceimpl.MyUserDetailsService.loadUserByUsername(MyUserDetailsService.java:33)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)
      at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
      at com.sun.proxy.$Proxy211.loadUserByUsername(Unknown Source)
      at org.springframework.security.authentication.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:114)
      ... 40 more
  Caused by: org.postgresql.util.PSQLException: ERROR: column userrole0_.user_id does not exist
    Position: 8
      at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2198)
      at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1927)
      at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
      at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:561)
      at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:419)
      at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:304)
      at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:82)
      ... 69 more
  </code></pre>
  
  <p>Here is my User class:</p>
  
  <pre><code>import java.io.Serializable;
  import java.util.HashSet;
  import java.util.LinkedHashSet;
  import java.util.Set;
  
  import javax.persistence.CascadeType;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.FetchType;
  import javax.persistence.Id;
  import javax.persistence.JoinColumn;
  import javax.persistence.JoinTable;
  import javax.persistence.ManyToMany;
  import javax.persistence.OneToMany;
  import javax.persistence.Table;
  
  @Entity
  @Table(name = "USERS")
  public class User implements Serializable {
  
      @Id
      @Column(name = "USER_ID", unique = true, nullable = false)
      private String userId;
  
      @Column(name = "USER_NAME")
      private String userName;
  
      @Column(name = "PASSWORD")
      private String password;
  
      @Column(name = "FIRST_NAME")
      private String firstName;
  
      @Column(name = "LAST_NAME")
      private String lastName;
  
      @Column(name = "DEFAULT_ROOM")
      private String defaultRoom;
  
      @Column(name = "VOICEMAIL_BOX")
      private String voicemailBox;
  
      @ManyToMany(cascade = { CascadeType.ALL })
      @JoinTable(name = "USERS_ROOMS", joinColumns = { @JoinColumn(name = "USER_ID") }, inverseJoinColumns = { @JoinColumn(name = "ROOM_ID") })
      private Set&lt;Room&gt; rooms = new LinkedHashSet&lt;Room&gt;();
  
      @OneToMany(cascade = { CascadeType.ALL })
      @JoinColumn(name = "USER_ID")
      private Set&lt;Extension&gt; extensions = new HashSet&lt;Extension&gt;();
  
      @Column(name = "LOGIN_PIN")
      private String loginPin;
  
      @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
      private Set&lt;UserRole&gt; userRole = new HashSet&lt;UserRole&gt;(0);
  
      @Column(name = "ENABLED")
      private boolean enabled;
  
      public User() {
          super();
      }
  
      public User(String userId) {
          this.userId = userId;
      }
  
      public String getUserId() {
          return userId;
      }
  
      public void setUserId(String userId) {
          this.userId = userId;
      }
  
      public String getUserName() {
          return userName;
      }
  
      public void setUserName(String userName) {
          this.userName = userName;
      }
  
      public String getPassword() {
          return password;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
      public String getFirstName() {
          return firstName;
      }
  
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
  
      public String getLastName() {
          return lastName;
      }
  
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
  
      public String getVoicemailBox() {
          return voicemailBox;
      }
  
      public void setVoicemailBox(String voicemailBox) {
          this.voicemailBox = voicemailBox;
      }
  
      public Set&lt;Room&gt; getRooms() {
          return rooms;
      }
  
      public void setRooms(Set&lt;Room&gt; rooms) {
          this.rooms = rooms;
      }
  
      public Set&lt;Extension&gt; getExtensions() {
          return extensions;
      }
  
      public void setExtensions(Set&lt;Extension&gt; extensions) {
          this.extensions = extensions;
      }
  
      public String getDefaultRoom() {
          return defaultRoom;
      }
  
      public void setDefaultRoom(String defaultRoom) {
          this.defaultRoom = defaultRoom;
      }
  
      public String getLoginPin() {
          return loginPin;
      }
  
      public void setLoginPin(String loginPin) {
          this.loginPin = loginPin;
      }
  
      public Set&lt;UserRole&gt; getUserRole() {
          return userRole;
      }
  
      public void setUserRole(Set&lt;UserRole&gt; userRole) {
          this.userRole = userRole;
      }
  
      public boolean isEnabled() {
          return enabled;
      }
  
      public void setEnabled(boolean enabled) {
          this.enabled = enabled;
      }
  
  }
  </code></pre>
  
  <p>My UserRole class:</p>
  
  <pre><code>import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.FetchType;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.JoinColumn;
  import javax.persistence.ManyToOne;
  import javax.persistence.Table;
  
  @Entity
  @Table(name = "USER_ROLE")
  public class UserRole {
  
      private String id;
      private User user;
      private String role;
  
      public UserRole() {
  
      }
  
      public UserRole(User user, String role) {
          this.user = user;
          this.role = role;
      }
  
      @Id
      @Column(name = "ID", unique = true, nullable = false)
      @GeneratedValue
      public String getId() {
          return id;
      }
  
      public void setId(String id) {
          this.id = id;
      }
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "USER_ID", nullable = false)
      public User getUser() {
          return user;
      }
  
      public void setUser(User user) {
          this.user = user;
      }
  
      public String getRole() {
          return role;
      }
  
      @Column(name = "ROLE")
      public void setRole(String role) {
          this.role = role;
      }
  
  }
  </code></pre>
  
  <p>As a reference I used the following tutorial: <a href="http://www.mkyong.com/spring-security/spring-security-hibernate-annotation-example/" rel="nofollow">http://www.mkyong.com/spring-security/spring-security-hibernate-annotation-example/</a></p>
  
  <p>EDIT: creation of the tables:
  1) user_role:</p>
  
  <pre><code>    CREATE TABLE user_role
  (
    id character varying NOT NULL,
    role character varying,
    CONSTRAINT id PRIMARY KEY (id),
    CONSTRAINT "user" FOREIGN KEY (id)
        REFERENCES users (user_id) MATCH SIMPLE
        ON UPDATE NO ACTION ON DELETE NO ACTION
  )
  </code></pre>
  
  <p>2) users:</p>
  
  <pre><code>    CREATE TABLE users
  (
    id serial NOT NULL,
    user_id character varying(16) NOT NULL,
    user_name character varying(16),
    password character varying(16),
    first_name character varying(16),
    last_name character varying(16),
    voicemail_box character varying(16),
    default_room character varying(16),
    login_pin character varying(4),
    enabled boolean,
    CONSTRAINT users_pkey PRIMARY KEY (user_id),
    CONSTRAINT users_fkey1 FOREIGN KEY (user_id)
        REFERENCES user_settings (user_id) MATCH SIMPLE
        ON UPDATE NO ACTION ON DELETE NO ACTION
  )
  </code></pre>
  
  <p>Any answers are appreciated :) sorry if it is a duplicate question. I will mark it as duplicate as soon as I have a clue what causes the error. Thank you!</p>