title: Example for Google Endpoint with Hibernate over Cloud SQL
body: <p>Does Google Endpoints work with Hibernate over Cloud SQL? <br>
  Can some post a short code example for it? <br>
  I tried to do so and encountered in general errors while generating a client library</p>
  
  <p>Language Class:</p>
  
  <pre><code>@Entity
  @Table(name = "LANGUAGES")
  public class Language  {
  
  private String languageIsoCode;
  private String languageName;
  
  public Language() {}
  
  @Id
  @Column(name = "LANGUAGE_ISO_CODE", unique = true, nullable = false, length = 8)
  public String getLanguageIsoCode() {
      return this.languageIsoCode;
  }
  
  public void setLanguageIsoCode(String languageIsoCode) {
      this.languageIsoCode = languageIsoCode;
  }
  
  @Column(name = "LANGUAGE_NAME", nullable = false, length = 160)
  public String getLanguageName() {
      return this.languageName;
  }
  
  public void setLanguageName(String languageName) {
      this.languageName = languageName;
  }
  }
  </code></pre>
  
  <p>LanguageEndpoint Class:</p>
  
  <pre><code>@Api
  public class LanguageEndpoint {
  
  @ApiMethod
  public String getLanguage(){
      EntityManager mgr = getEntityManager();
      Query q = mgr.createQuery("from Language");
      Language l = (Language) q.getResultList().get(0);
      return l.getLanguageName();
  }
  
  private static EntityManager getEntityManager() {
      return EMF.hibernateGet().createEntityManager();
  }
  
  }
  </code></pre>
  
  <p>and EMF class:</p>
  
  <pre><code>public final class EMF {
  private static final EntityManagerFactory emfInstance = Persistence
          .createEntityManagerFactory("transactions-optional");
  
  private static final EntityManagerFactory emfHibernateInstance = Persistence
          .createEntityManagerFactory("com.google.cloudsql.jpa");
  
  private EMF() {
  }
  
  public static EntityManagerFactory get() {
      return emfInstance;
  }
  
  public static EntityManagerFactory hibernateGet() {
      return emfHibernateInstance;
  }
  }
  </code></pre>