Google エンドポイントは Hibernate over Cloud SQL で動作しますか?
短いコード例を投稿できますか?
そうしようとしたところ、クライアント ライブラリの生成中に一般的なエラーが発生しました
言語クラス:
@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;
}
}
LanguageEndpoint クラス:
@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();
}
}
および EMF クラス:
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;
}
}