title: Hibernate Criteria Api with Inner Join and Many to Many
body: <p>I'm new with Hibernate and Criteria Query.
  How can I implement it with Hibernate Criteria Object?</p>
  
  <pre><code>SELECT stateslocalization.StateId, stateslocalization.localization AS name
  FROM processstate
  Join states ON  states.id = processstate.StateId
  JOIN stateslocalization ON stateslocalization.StateId = states.id
  WHERE processstate.ProcessId = 38 and processstate.StateId = states.id AND stateslocalization.StateId = states.id
  </code></pre>
  
  <p>Entities:</p>
  
  <p>Process:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Entity
  @Table(name = "processes")
  public class Process {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private int id;
  
      private String name;
  
      @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
      @JoinTable(
          name = "processstate",
          joinColumns = {@JoinColumn(name = "ProcessId")},
          inverseJoinColumns = {@JoinColumn(name = "StateId")}
      )
      private Set&lt;State&gt; states;
  
      //getters and setters.....
  }
  </code></pre>
  
  <p>State:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Entity
  @Table(name = "states") 
  public class State {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "id")
      private int id;
  
      private String name;
  
      @ManyToMany(mappedBy = "states", cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
      private Set&lt;Process&gt; processes;
  
      @OneToOne(mappedBy = "state")
      private StateLocalization stateLocalization;
  
      //getters and setters.....
  }
  </code></pre>
  
  <p>StateLocalization:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Entity
  @Table(name = "stateslocalization")
  public class StateLocalization {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private int id;
  
      @OneToOne(cascade = CascadeType.ALL)
      @JoinColumn(name = "StateId", referencedColumnName = "id")
      private State state;
  
      private String localization;
  
      //getters and setters.....
  }
  </code></pre>
  
  <p>I did it with native query but I don't know how I can implement it to Hibernate Criteria, because I don't have entity processstate (it's only table).</p>