我正在嘗試設置爪哇。在我的項目中堅持不懈,我已經開始使用基本方法:實體管理器生成器 package olsa.amex.dao; import javax.persistence.*; public class EntityManagerGenerator {private EntityManager currentSession;private EntityTransaction currentTransaction;public EntityManager openCurrentSession() { if ((currentSession == null)||(currentSession != null && !currentSession.isOpen())) currentSession = getSessionFactory().createEntityManager(); return currentSession;}public EntityManager openCurrentSessionwithTransaction() { if ((currentSession == null)||(currentSession != null && !currentSession.isOpen())) currentSession = getSessionFactory().createEntityManager(); currentTransaction = currentSession.getTransaction(); currentTransaction.begin(); return currentSession;}public void closeCurrentSession() { if (currentSession != null && currentSession.isOpen()) currentSession.close();}public void closeCurrentSessionwithTransaction() { if (currentSession != null && currentSession.isOpen()) { currentTransaction.commit(); currentSession.close(); }}private static EntityManagerFactory getSessionFactory() { EntityManagerFactory entityManager = Persistence.createEntityManagerFactory("JPAAmex"); return entityManager;}public EntityManager getCurrentSession() { return currentSession;}public void setCurrentSession(EntityManager currentSession) { this.currentSession = currentSession;}public EntityTransaction getCurrentTransaction() { return currentTransaction;}public void setCurrentTransaction(EntityTransaction currentTransaction) { this.currentTransaction = currentTransaction;}}
1 回答

莫回無
TA貢獻1865條經驗 獲得超7個贊
我發現了問題,顯然這都是由錯誤的jdbc連接字符串引起的。為了生成實體,我使用了以下字符串:
jdbc:mysql://rmarjboss-001c.customer.olsa:3306/amex_digital_sbs_dev?useUnicode=yes&characterEncoding=UTF-8
我在堅持中使用的.xml是這樣的:
jdbc:mysql://rmarjboss-001c.customer.olsa:3306/amex_digital_sbs_dev
為了使一切正常工作,我必須在持久性中設置正確的字符串.xml:
jdbc:mysql://rmarjboss-001c.customer.olsa:3306/amex_digital_sbs_dev?useUnicode=yes&characterEncoding=UTF-8
添加回答
舉報
0/150
提交
取消