我正在尝试设置爪哇。在我的项目中坚持不懈,我已经开始使用基本方法:实体管理器生成器 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
提交
取消