title: WARN: SQL Error: 1064, SQLState: 42000
body: <p>I have a problem with hibernate query. </p>
  
  <p>UPDATE:
  When I use this query it works like a charm:</p>
  
  <pre><code>public static List&lt;Korisnik&gt; UzmiSveKorisnike()
      {
          EntityManager em = Konekcija.getEmf().createEntityManager();
  
          TypedQuery&lt;Korisnik&gt; q = em.createQuery("select k from Korisnik k where k.isActive = 1", Korisnik.class); 
          List&lt;Korisnik&gt; resultList = q.getResultList();
  
          em.close();
          return resultList;
      }
  </code></pre>
  
  <p>But when I use one listed below, to select single result (like for login)...</p>
  
  <p>I get this error: WARN: SQL Error: 1064, SQLState: 42000</p>
  
  <p>I have tried variety of ways to implement this query, but without success. I will list them at the end of the post. </p>
  
  <p>This is the code:</p>
  
  <pre><code>public static Korisnik ProvjeraKorisnickihPodataka(String kIme, String kLozinka)
      {
          EntityManager em = Konekcija.getEmf().createEntityManager();
  
      {
          TypedQuery&lt;Korisnik&gt; q = em.createQuery("select k from Korisnik k where k.isActive = 1 AND k.korisnickoIme=:ime AND k.lozinka =:lozinka", Korisnik.class); 
          q.setParameter("ime", kIme);
          q.setParameter("lozinka", kLozinka);
          Korisnik provjeren = q.getSingleResult();
  
          em.close();
  
          return provjeren;
  </code></pre>
  
  <p>Even if I replace :ime and :lozinka with actual data like "k.korisnickoIme='msbtest' and k.lozinka = 'msbtest'" I get the same error.</p>
  
  <p>Your help is appreciated.</p>
  
  <p>Thank you!</p>
  
  <p>Complete stack:</p>
  
  <pre><code>Hibernate: select TOP(?) korisnik0_.KorisnikID as KorisnikID11_, korisnik0_.agencija_AgencijaID as agencija8_11_, korisnik0_.ime as ime11_, korisnik0_.isActive as isActive11_, korisnik0_.kontakt as kontakt11_, korisnik0_.korisnickoIme as korisnic5_11_, korisnik0_.lozinka as lozinka11_, korisnik0_.prezime as prezime11_, korisnik0_.rola_RolaID as rola9_11_ from Korisnik korisnik0_ where korisnik0_.isActive=1 and korisnik0_.korisnickoIme=? and korisnik0_.lozinka=?
  Jul 05, 2013 11:45:22 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
  WARN: SQL Error: 1064, SQLState: 42000
  Jul 05, 2013 11:45:22 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
  ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.KorisnikID as KorisnikID11_, korisnik0_.agencija_AgencijaID as agencija8_11_, k' at line 1
  javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.KorisnikID as KorisnikID11_, korisnik0_.agencija_AgencijaID as agencija8_11_, k' at line 1
      at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1377)
      at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1300)
      at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:318)
      at Servis.LoginServis.ProvjeraKorisnickihPodataka(LoginServis.java:35)
      at UI.LogInFrm.do_btnPrijava_widgetSelected(LogInFrm.java:173)
      at UI.LogInFrm$1.widgetSelected(LogInFrm.java:121)
      at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
      at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
      at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
      at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
      at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
      at UI.LogInFrm.main(LogInFrm.java:44)
  Caused by: org.hibernate.exception.SQLGrammarException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.KorisnikID as KorisnikID11_, korisnik0_.agencija_AgencijaID as agencija8_11_, k' at line 1
      at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82)
      at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
      at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
      at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
      at com.sun.proxy.$Proxy10.executeQuery(Unknown Source)
      at org.hibernate.loader.Loader.getResultSet(Loader.java:1926)
      at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1727)
      at org.hibernate.loader.Loader.doQuery(Loader.java:852)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:293)
      at org.hibernate.loader.Loader.doList(Loader.java:2411)
      at org.hibernate.loader.Loader.doList(Loader.java:2397)
      at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2227)
      at org.hibernate.loader.Loader.list(Loader.java:2222)
      at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
      at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
      at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1247)
      at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
      at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:285)
      ... 9 more
  Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.KorisnikID as KorisnikID11_, korisnik0_.agencija_AgencijaID as agencija8_11_, k' at line 1
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Unknown Source)
      at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
      at com.mysql.jdbc.Util.getInstance(Util.java:386)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
      at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
      at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
      at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2734)
      at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
      at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2322)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
      ... 25 more
  </code></pre>
  
  <p>mapping goes like this:</p>
  
  <pre><code>/**
   ** Class Korisnik
   **/
      @Entity
  public class Korisnik implements Serializable { 
    //Fields
      @Id
      @GeneratedValue
    private Integer KorisnikID;
    private String ime;
    private String prezime;
    private String kontakt;
    private String korisnickoIme;
    private String lozinka;
    private Boolean isActive;
      @JoinColumn(nullable = false)
      @ManyToOne
    private Agencija agencija;
      @JoinColumn(nullable = false)
      @ManyToOne
    private Rola rola;
  </code></pre>
  
  <p>and getters and setters go...</p>
  
  <p>OK, my persistence.xml file looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
      &lt;persistence-unit name="MojaOznaka1" transaction-type="RESOURCE_LOCAL"&gt;
          &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
          &lt;properties&gt;
              &lt;!-- Podaci o bazi podataka --&gt;
              &lt;property name="javax.persistence.jdbc.url" value="jdbc:mysql://xxxxxxxxx.xxxxxxxxx.xxx/xxxxxxxxx/" /&gt;
              &lt;property name="javax.persistence.jdbc.user" value="xxxxxx" /&gt;
              &lt;property name="javax.persistence.jdbc.password" value="xxxxxx" /&gt;
              &lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /&gt;
  
  
              &lt;!-- hiberante dialect --&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2008Dialect" /&gt;
              &lt;!-- JDBC connection pool (use the built-in) --&gt;
              &lt;property name="connection.pool_size" value="1" /&gt;
              &lt;!-- Ispis SQL koda u konzolu --&gt;
              &lt;property name="hibernate.show_sql" value="true" /&gt;
              &lt;!-- formatiranje SQL koda ispisanog u konzolni prozor --&gt;
              &lt;property name="hibernate.format_sql" value="false" /&gt;
              &lt;!-- Vrijednost "update" kreira tabele ako nepostoje --&gt;
                      &lt;!-- &lt;property name="hibernate.hbm2ddl.auto" value="update" /&gt; --&gt;
              &lt;!-- Enable Hibernate's automatic session context management --&gt;
              &lt;property name="current_session_context_class" value="thread" /&gt;
              &lt;!-- Disable the second-level cache --&gt;
              &lt;property name="cache.provider_class" value="org.hibernate.cache.NoCacheProvider" /&gt;
              &lt;!-- automatsko prepoznavanje JPA klasa --&gt;
              &lt;property name="hibernate.archive.autodetection" value="class, hbm" /&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>OK, now what???</p>