将项目jar文件导出到文件服务器后,jpa的entitymanager的创建不再起作用。
有以下详细信息:
这是persistence.xml的内容
<?xml version="1.0" encoding="UTF-8"?>
<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"
version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="QIS" transaction-type="RESOURCE_LOCAL" >
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.quoka.qis.lib.persistence.Type</class>
</persistence-unit>
</persistence>
整个事情在eclipse中工作,但不是从文件服务器。 : - )
错误信息是:
org.eclipse.persistence.internal.jpa.deployment.xml.parser.XMLException
URI was not reported to parser for entity [document])
Caused By:
Log Exception of type org.eclipse.persistence.internal.jpa.deployment.xml.parser.XMLException :
(1. URI was not reported to parser for entity [document])
(0) org.eclipse.persistence.internal.jpa.deployment.xml.parser.XMLExceptionHandler.error(XMLExceptionHandler.java:28)
(1) org.eclipse.persistence.internal.jpa.deployment.xml.parser.XMLExceptionHandler.warning(XMLExceptionHandler.java:23)
(2) gnu.xml.aelfred2.SAXDriver.warn(SAXDriver.java:935)
(3) gnu.xml.aelfred2.SAXDriver.startExternalEntity(SAXDriver.java:631)
(4) gnu.xml.aelfred2.XmlParser.pushURL(XmlParser.java:3358)
(5) gnu.xml.aelfred2.XmlParser.doParse(XmlParser.java:159)
(6) gnu.xml.aelfred2.SAXDriver.parse(SAXDriver.java:320)
(7) gnu.xml.aelfred2.XmlReader.parse(XmlReader.java:294)
(8) org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceXML(PersistenceUnitProcessor.java:442)
(9) org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceArchive(PersistenceUnitProcessor.java:401)
(10) org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.getPersistenceUnits(PersistenceUnitProcessor.java:310)
(11) org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfoInArchive(JPAInitializer.java:149)
(12) org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfoInArchives(JPAInitializer.java:136)
(13) org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfo(JPAInitializer.java:125)
(14) org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:98)
(15) org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:65)
(16) javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:78)
(17) com.quoka.qis.admin.QisAdminEntityManager.getInstance(QisAdminEntityManager.java:33)
(18) com.quoka.qis.admin.QisAdminFrame.login(QisAdminFrame.java:574)
(19) com.quoka.qis.admin.QisAdminFrame.testLogin(QisAdminFrame.java:513)
(20) com.quoka.qis.admin.QisAdminFrame.showFrame(QisAdminFrame.java:441)
(21) com.quoka.qis.admin.QisAdminFrame.showFrame(QisAdminFrame.java:417)
(22) com.quoka.qis.admin.QisAdminFrame.access$3(QisAdminFrame.java:416)
(23) com.quoka.qis.admin.QisAdminFrame$DebugPanel.run(QisAdminFrame.java:777)
(24) java.lang.Thread.run(Thread.java:662)
DBConnection是:
Map<String, String> properties = new HashMap<String, String>();
properties.put("javax.persistence.jdbc.driver", "com.sybase.jdbc3.jdbc.SybDriver");
properties.put("eclipselink.target-database", "Sybase");
properties.put("javax.persistence.jdbc.url", "jdbc:sybase:Tds:"+meta.getServerName()+":"+meta.getPort());
properties.put("javax.persistence.jdbc.user", meta.getUserName());
properties.put("javax.persistence.jdbc.password", meta.getPassword());
properties.put("eclipselink.logging.level", "INFO");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("QIS", properties);
em = emf.createEntityManager();
答案 0 :(得分:1)
persistence.xml文件格式正确,因此错误可能与由于混乱类路径而被调用的错误SAX解析器有关。我的建议是仔细检查你的应用程序类路径,特别是检查包含的jar是否包含重复和不兼容的SAX解析器。
答案 1 :(得分:0)
假设您的句子“将项目jar文件导出到文件服务器后”意味着您将项目部署到Glassfish中,您问题的答案如下:
您的问题是您正在为部署到glassfish的应用程序创建其事务类型为“resource-local”的EntityManager。您的应用程序 - 一旦部署在GlassFish之类的任何应用程序服务器中 - 实际上是由容器管理的,它不再是SE的EE应用程序。容器管理的EntityManager必须具有JTA事务类型。
请按照以下步骤操作或参考this Link或参考this Link设置您的JTA交易类型:
添加以下属性:
URL = jdbc:sybase:Tds:“输入您的ServerName”:“输入您的端口”
用户=输入
密码=输入
按“确定”
返回persistence.xml,按如下所示进行修改:
persistence-unit name =“QIS”transaction-type =“JTA”
JTA - 数据 - 源&GT; HasanSybaseJNDI
重新部署,你就定了。
虽然您必须修改代码以丢失任何事务处理。这意味着代码中不再需要以下两行:
。em.getTransaction()开头(); em.getTransaction()提交();
Glassfish应用程序服务器为您处理事务!