title: Could not extract result in hibernate?
body: <p>I can't extract result in hibernate.. I want to check an account when they sign in but it throws an exception: could not extract result. </p>
  
  <p>My sample code:</p>
  
  <p>My Pojo:</p>
  
  <pre><code>@Entity
  @Table(name = "account")
  public class TestAccount implements Serializable {
  
      @Id
      @Column(name="IDACCOUNT")
      private Integer idAccount;
  
      @Column(name="USERNAME")
      private String username;
  
      @Column(name="PASSWORD")
      private String password;
  
      @Column(name="ISDELETED")
      private Integer isDeleted;
  
      @ManyToOne
      @JoinColumn(name="ROLE")
      private TestAccountRole accountRole;
  
      @OneToOne(mappedBy="accountInfo", cascade=CascadeType.ALL)
      private TestAccountInfo accountInfo;
  }
  </code></pre>
  
  <hr>
  
  <pre><code>@Entity
  @Table(name = "account_role")
  public class TestAccountRole implements Serializable {
      @Id
      @Column(name="IDACCOUNT_ROLE")
      private Integer idAccountRole;
  
      @Column(name="ROLE")
      private String role;
  
      @OneToMany(mappedBy="accountRole", fetch = FetchType.LAZY)
      private Set&lt;TestAccount&gt; accounts = new HashSet&lt;TestAccount&gt;(0);
  }
  </code></pre>
  
  <hr>
  
  <pre><code>@Entity
  @Table(name = "account")
  public class TestAccountInfo implements Serializable {
  
      @Id
      @Column(name="IDACCOUNT_INFO")
      private Integer idAccountInfo;
  
      @Column(name = "BIRTHDAY")
      private String birthday;
  
      @Column(name = "SEX")
      private String sex;
  
      @Column(name = "ADDRESS")
      private String address;
  
      @Column(name = "EMAIL")
      private String email;
  
      @Column(name = "PHONE")
      private String phone;
  
      @Column(name = "ISDELETED")
      private Integer isDeleted;
  
      @OneToOne
      @PrimaryKeyJoinColumn
      private TestAccount accountInfo;
  }
  </code></pre>
  
  <p>My Dao:</p>
  
  <pre><code>public TestAccount Authenticate(String username, String password) {
  
      String passMD5 = AccountUtil.md5(password);
      Session session = sessionFactory.getCurrentSession();
      String sql = "from Account where username = ? and password = ?";
      Query query = session.createQuery(sql);
      query.setString(0, username);
      query.setString(1, passMD5);
      //query.setInteger(2, 0);
      TestAccount account = (TestAccount) query.uniqueResult();
      if (account != null) {
        return account;
      }
      return null;
  }
  </code></pre>
  
  <p>My Db:</p>
  
  <pre><code>CREATE TABLE `account` (
    `IDACCOUNT` int(11) NOT NULL AUTO_INCREMENT,
    `USERNAME` varchar(45) DEFAULT NULL,
    `PASSWORD` varchar(45) DEFAULT NULL,
    `ISDELETED` int(11) DEFAULT NULL,
    `ROLE` int(11) DEFAULT NULL,
    PRIMARY KEY (`IDACCOUNT`),
    KEY `ROLEACCOUNT_idx` (`ROLE`),
    CONSTRAINT `ROLEACCOUNT` FOREIGN KEY (`ROLE`) REFERENCES `account_role` (`IDACCOUNT_ROLE`) ON DELETE NO ACTION ON UPDATE NO ACTION
  )
  
  CREATE TABLE `account_info` (
    `IDACCOUNT_INFO` int(11) NOT NULL AUTO_INCREMENT,
    `BIRTHDAY` varchar(45) DEFAULT NULL,
    `SEX` varchar(45) DEFAULT NULL,
    `ADDRESS` varchar(45) DEFAULT NULL,
    `EMAIL` varchar(45) DEFAULT NULL,
    `PHONE` varchar(12) DEFAULT NULL,
    `ISDELETED` int(11) DEFAULT NULL,
    PRIMARY KEY (`IDACCOUNT_INFO`),
    CONSTRAINT `ACCOUNTINFO` FOREIGN KEY (`IDACCOUNT_INFO`) REFERENCES `account` (`IDACCOUNT`) ON DELETE NO ACTION ON UPDATE NO ACTION
  )
  
  CREATE TABLE `account_role` (
    `IDACCOUNT_ROLE` int(11) NOT NULL AUTO_INCREMENT,
    `ROLE` varchar(45) DEFAULT NULL,
    PRIMARY KEY (`IDACCOUNT_ROLE`)
  ) 
  </code></pre>
  
  <p>An exception</p>
  
  <pre><code>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
  
  root cause
  
  org.hibernate.exception.SQLGrammarException: could not extract ResultSet
      org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82)
      org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
      org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
      org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
      org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:61)
      org.hibernate.loader.Loader.getResultSet(Loader.java:2040)
      org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1837)
  
  
  root cause
  
  com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'account0_.IDACCOUNTROLE' in 'field list'
      sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
      sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
      java.lang.reflect.Constructor.newInstance(Unknown Source)
      com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
      com.mysql.jdbc.Util.getInstance(Util.java:386)
      com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
      com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
      com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
  </code></pre>