title: Error executing a Query using JPA
body: <p>I'm trying to sort a resultset using the SQL statement Order by using JPA, on a datetime column data type with this string, on a Mysql database:</p>
  
  <pre><code>Query query = em.createQuery("SELECT e FROM Events e Order by e.EventDateTime;");
  </code></pre>
  
  <p>Using the createQuery method java returns the error:</p>
  
  <pre><code>SEVERE: Local Exception Stack: 
  Exception [EclipseLink-8030] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): 
  
  org.eclipse.persistence.exceptions.JPQLException
  Exception Description: Error compiling the query [Events.findByGameId: SELECT e FROM Events e WHERE e.gameId = 
  
  :gameId ORDER BY e.EventDateTime DESC], line 1, column 59: unknown state or association field [EventDateTime] of class [com.jogogestao.entity.Events].
      at org.eclipse.persistence.exceptions.JPQLException.unknownAttribute(JPQLException.java:457)
      at org.eclipse.persistence.internal.jpa.parsing.DotNode.validate(DotNode.java:88)
      at org.eclipse.persistence.internal.jpa.parsing.OrderByItemNode.validate(OrderByItemNode.java:52)
      at org.eclipse.persistence.internal.jpa.parsing.OrderByNode.validate(OrderByNode.java:61)
  at org.eclipse.persistence.internal.jpa.parsing.ParseTree.validate(ParseTree.java:210)
  </code></pre>
  
  <p>I tried sorting by the integer type primary and all runs ok...but this is not what I want of course.
  Using createNativeQuery the statement runs ok...</p>
  
  <pre><code>Query query = em.createNativeQuery("SELECT * FROM Events Order by EventDateTime;");
  </code></pre>
  
  <p>The only problem is that the return object is not an Events type object (from the entity) and I can't convert to this type.</p>
  
  <p>Maybe the problem is that JPA does not support sorting on datetime fields?</p>
  
  <p>How can I get around this?</p>
  
  <p>I'm using Netbeans 7.0.1, Glassfish 3.1.1, MySql 5.5.19  Community Server (GPL) and mysql-connector-java-5.1.15-bin.jar.</p>
  
  <p>Thanks!</p>