0
Google Endpoints是否與Hibernate over Cloud SQL一起使用?
有人可以發佈一個簡短的代碼示例嗎?
我試圖這樣做,一般遇到的錯誤而產生的客戶端庫Google Endpoint與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;
}
}
請發佈您嘗試的代碼,我們會盡力幫助。雲端點運行在App Engine上,因此您可以在雲端點方法中執行任何操作,您可以在App Engine中的任何其他位置執行任何操作。 – bossylobster 2013-03-23 16:17:06
發佈了代碼。如果你看一下,我將不勝感激。謝謝 – 2013-03-28 17:50:33