title: Unexpected token error with JPA, Hibernate and QueryDSL
body: <p>I'm developing a <strong>Data Access Layer</strong> based on <strong>JPA</strong> by using <strong>Hibernate</strong> as <strong>ORM</strong> and <strong>QueryDSL</strong> in order to write <em>type-safe</em> queries.</p>
  
  <p>My <code>persistence.xml</code> is as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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="PrismaDAL" transaction-type="JTA"&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
        &lt;jta-data-source&gt;java:jboss/datasources/PRISMA/PRISMA-DS&lt;/jta-data-source&gt;
         &lt;properties&gt;
      &lt;property name="hibernate.max_fetch_depth" value="3" /&gt;
      &lt;property name="hibernate.show_sql" value="false" /&gt;
      &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /&gt;
      &lt;property name="hibernate.id.new_generator_mappings" value="true" /&gt;
      &lt;property name="hibernate.default_catalog" value="test_prisma_paas"/&gt;
      &lt;property name='hibernate.hbm2ddl.auto' value='update' /&gt;
    &lt;/properties&gt;
    &lt;/persistence-unit&gt;
  </code></pre>
  
  <p></p>
  
  <p>Then, my <code>Organization</code> entity:</p>
  
  <pre><code>import static javax.persistence.GenerationType.IDENTITY;
  
  import java.util.Date;
  import java.util.HashSet;
  import java.util.Set;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.FetchType;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.OneToMany;
  import javax.persistence.Table;
  import javax.persistence.Temporal;
  import javax.persistence.TemporalType;
  
  /**
   * Organization generated by hbm2java
   */
  @Entity
  @Table(name = "Organization")
  public class Organization implements java.io.Serializable {
  
    private Long organizationId;
    private String name;
    private String description;
    private String logoUri;
    private String websiteUri;
    private String websiteLabel;
    private Date createdAt;
    private Date modifiedAt;
    private Set&lt;Workgroup&gt; workgroups = new HashSet&lt;Workgroup&gt;(0);
    private Set&lt;OrganizationReferent&gt; organizationReferents = new HashSet&lt;OrganizationReferent&gt;(
        0);
    private Set&lt;IdentityProvider&gt; identityProviders = new HashSet&lt;IdentityProvider&gt;(
        0);
  
    public Organization() {
    }
  
    public Organization(String name, String description, Date createdAt,
        Date modifiedAt) {
      this.name = name;
      this.description = description;
      this.createdAt = createdAt;
      this.modifiedAt = modifiedAt;
    }
  
    public Organization(String name, String description, String logoUri,
        String websiteUri, String websiteLabel, Date createdAt,
        Date modifiedAt, Set&lt;Workgroup&gt; workgroups,
        Set&lt;OrganizationReferent&gt; organizationReferents,
        Set&lt;IdentityProvider&gt; identityProviders) {
      this.name = name;
      this.description = description;
      this.logoUri = logoUri;
      this.websiteUri = websiteUri;
      this.websiteLabel = websiteLabel;
      this.createdAt = createdAt;
      this.modifiedAt = modifiedAt;
      this.workgroups = workgroups;
      this.organizationReferents = organizationReferents;
      this.identityProviders = identityProviders;
    }
  
    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "organizationID", unique = true, nullable = false)
    public Long getOrganizationId() {
      return this.organizationId;
    }
  
    public void setOrganizationId(Long organizationId) {
      this.organizationId = organizationId;
    }
  
    @Column(name = "name", nullable = false, length = 45)
    public String getName() {
      return this.name;
    }
  
    public void setName(String name) {
      this.name = name;
    }
  
    @Column(name = "description", nullable = false, length = 65535)
    public String getDescription() {
      return this.description;
    }
  
    public void setDescription(String description) {
      this.description = description;
    }
  
    @Column(name = "logoURI", length = 2083)
    public String getLogoUri() {
      return this.logoUri;
    }
  
    public void setLogoUri(String logoUri) {
      this.logoUri = logoUri;
    }
  
    @Column(name = "websiteURI", length = 2083)
    public String getWebsiteUri() {
      return this.websiteUri;
    }
  
    public void setWebsiteUri(String websiteUri) {
      this.websiteUri = websiteUri;
    }
  
    @Column(name = "websiteLabel", length = 100)
    public String getWebsiteLabel() {
      return this.websiteLabel;
    }
  
    public void setWebsiteLabel(String websiteLabel) {
      this.websiteLabel = websiteLabel;
    }
  
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "createdAt", nullable = false, length = 19, insertable = false, updatable = false)
    public Date getCreatedAt() {
      return this.createdAt;
    }
  
    public void setCreatedAt(Date createdAt) {
      this.createdAt = createdAt;
    }
  
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "modifiedAt", nullable = false, length = 19, insertable = false)
    public Date getModifiedAt() {
      return this.modifiedAt;
    }
  
    public void setModifiedAt(Date modifiedAt) {
      this.modifiedAt = modifiedAt;
    }
  
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "organization")
    public Set&lt;Workgroup&gt; getWorkgroups() {
      return this.workgroups;
    }
  
    public void setWorkgroups(Set&lt;Workgroup&gt; workgroups) {
      this.workgroups = workgroups;
    }
  
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "organization")
    public Set&lt;OrganizationReferent&gt; getOrganizationReferents() {
      return this.organizationReferents;
    }
  
    public void setOrganizationReferents(
        Set&lt;OrganizationReferent&gt; organizationReferents) {
      this.organizationReferents = organizationReferents;
    }
  
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "organization")
    public Set&lt;IdentityProvider&gt; getIdentityProviders() {
      return this.identityProviders;
    }
  
    public void setIdentityProviders(Set&lt;IdentityProvider&gt; identityProviders) {
      this.identityProviders = identityProviders;
    }
  
  }
  </code></pre>
  
  <p>In closing, my <code>OrganizationDAO</code>'s method:</p>
  
  <pre><code>public long count() {
    JPAQuery jpaQuery = new JPAQuery(em);
    PathBuilder&lt;Organization&gt; qOrganization = new PathBuilder&lt;Organization&gt;(Organization.class, 
              Introspector.decapitalize(Organization.class.getName()));
    return jpaQuery.from(qOrganization).count();
  }
  </code></pre>
  
  <p>By running this code, the application returns me an error as follows:</p>
  
  <pre><code>java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: . near line 2, column 55 [select count(it.prisma.dal.entities.accounting.Organization)
  from it.prisma.dal.entities.accounting.Organization it.prisma.dal.entities.accounting.Organization]
  </code></pre>
  
  <p>What am I doing wrong? How can I fix it?</p>