我正在使用 Java + BlazeDS + MySQL + Flash Builder + EclipseLink (JPA 2.1) + Tomcat 7 (Windows)
问题是这样的,当我在 Netbeans 中编译我的应用程序时,与数据库的连接工作得很好。但是当我使用war文件直接在tomcat中进行部署时,它不会访问数据库。
我尝试了多个版本的 tomcat,包括 tomcat netbeans,但它不起作用。仅当我从 Netbeans 中运行项目时才有效
我几乎疯了试图解决它,有人经历过这个问题吗?
我真的很感激任何帮助
我的 persistence.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="goncricPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>entidade.sancric</class>
<class>entidade.logincric</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/derea? zeroDateTimeBehavior=convertToNull"/>
<property name="javax.persistence.jdbc.password" value="qwaszx"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="derea"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>
…………
使数据库持久化的文件:
*/
public class persistir {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("goncricPU");
public void persist(Object object) {
EntityManager em = emf.createEntityManager();
try {
em.getTransaction().begin();
em.persist(object);
em.getTransaction().commit();
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", e);
em.getTransaction().rollback();
} finally {
em.close();
}
}
}