After exporting the project jar file to the fileserver the creation of the entitymanager of jpa does not work anymore.
There is following details:
this is the content of the 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>
The whole thing works inside eclipse but not from the fileserver. :-)
Error message is:
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 is:
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();
The persistence.xml file is well-formed so the error could be related to a wrong SAX parser being called as a result of a messed classpath. My advise is to carefully review your application classpath, especially checking if included jars contain duplicate and incompatible SAX parsers.
Assuming that your sentence "After exporting the project jar file to the fileserver" means that you deployed your project into Glassfish, the answer to your question is as follows:
Your problem is that you are creating an EntityManager whose transaction type is "resource-local" for an application that you deployed into glassfish. Your application - once deployed within any application server like GlassFish - is in fact managed by the container and it is an EE application not SE anymore. The EntityManager to be managed by the container has to have a JTA transaction type.
Follow these steps or refer to this Link or refer to this Link to setup your JTA transaction type:
Add the following properties:
URL= jdbc:sybase:Tds:"type your ServerName":"type your Port"
User = type it
Password = type it
Push OK
Back to your persistence.xml, modify it as follows:
persistence-unit name="QIS" transaction-type="JTA"
jta-data-source>HasanSybaseJNDI
Redeploy and you are set.
Although you have to modify your code as to lose any transaction handling. Meaning the following 2 lines are not needed in your code anymore:
em.getTransaction().begin(); em.getTransaction().commit();
The Glassfish application server handles transactions for you!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.