Ich bin neu bei JPA und ich bin ziemlich verloren in diesem.javax.persistence.PersistenceException: Kein Persistence Provider für EntityManager namens Eclipselink_JPA
Ich habe ein Enterprise-Projekt in Netbeans erstellt, um einige Tests durchzuführen. Diese Persistenzeinheit wurde mit dem Assistenten erstellt. Ich habe es eine JNDI-Verbindung, die richtige funktioniert und es ist bereits getestet:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="persistencia" transaction-type="JTA">
<jta-data-source>jdbc/nuevaConexion</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
</properties>
</persistence-unit>
</persistence>
Später habe ich eine Probe Entität mit einigen Testvariablen erstellt, um zu sehen, wie das funktioniert:
@Entity
public class Entity1 implements Serializable {
private static long serialVersionUID = 1L;
private String nombre;
private int numero;
/**
* @return the serialVersionUID
*/
public static long getSerialVersionUID() {
return serialVersionUID;
}
/**
* @param aSerialVersionUID the serialVersionUID to set
*/
public static void setSerialVersionUID(long aSerialVersionUID) {
serialVersionUID = aSerialVersionUID;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
// setters & getters
Dann versuchte zu machen der Service CreateEntity1 es einen Versuch geben und versuchen, ein neues Element auf dem DB zu schaffen, indem sie rufen:
public class CreateEntity1 {
public static void main(String[ ] args) {
EntityManagerFactory emfactory = Persistence.createEntityManagerFactory("Eclipselink_JPA");
EntityManager entitymanager = emfactory.createEntityManager();
entitymanager.getTransaction().begin();
Entity1 ent = new Entity1();
ent.setId(1);
ent.setNombre("Mi entidad");
ent.setNumero(123);
entitymanager.persist(ent);
entitymanager.getTransaction().commit();
entitymanager.close();
emfactory.close();
}
}
... aber es funktioniert nicht. Ich erhalte folgende Fehlermeldung:
Was mache ich falsch?
EDIT: Ich änderte den Namen des Persistenz-Providers zu dem guten, aber jetzt bekomme ich eine Reihe von Fehlern.
EDIT 2: Alles auf den Hibernate-Typ geändert. Noch einen großen Fehler bekommen:
Exception in thread "main" Local Exception Stack: Exception [EclipseLink-30009] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException Exception Description: An exception was thrown while trying to load persistence unit at url: file:/C:/Users/hp/Documents/NetBeansProjects/PruebasJ2EE/PruebasJ2EE-ejb/build/classes/ Internal Exception: Exception [EclipseLink-30004] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException Exception Description: An exception was thrown while processing persistence.xml from URL: file:/C:/Users/hp/Documents/NetBeansProjects/PruebasJ2EE/PruebasJ2EE-ejb/build/classes/ Internal Exception: (1. El destino de la instrucción de procesamiento que coincide con "[xX][mM][lL]" no está permitido.) at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionLoadingFromUrl(PersistenceUnitLoadingException.java:100) at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceArchive(PersistenceUnitProcessor.java:616) at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.getPersistenceUnits(PersistenceUnitProcessor.java:500) at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfoInArchive(JPAInitializer.java:178) at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfoInArchives(JPAInitializer.java:160) at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfo(JPAInitializer.java:141) at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:188) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54) at service.CreateEntity1.main(CreateEntity1.java:22) Caused by: Exception [EclipseLink-30004] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException Exception Description: An exception was thrown while processing persistence.xml from URL: file:/C:/Users/hp/Documents/NetBeansProjects/PruebasJ2EE/PruebasJ2EE-ejb/build/classes/ Internal Exception: (1. El destino de la instrucción de procesamiento que coincide con "[xX][mM][lL]" no está permitido.) at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionProcessingPersistenceXML(PersistenceUnitLoadingException.java:118) at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceXML(PersistenceUnitProcessor.java:665) at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceArchive(PersistenceUnitProcessor.java:614) ... 8 more Caused by: (1. El destino de la instrucción de procesamiento que coincide con "[xX][mM][lL]" no está permitido.) at org.eclipse.persistence.internal.jpa.deployment.xml.parser.XMLExceptionHandler.error(XMLExceptionHandler.java:28) at org.eclipse.persistence.internal.jpa.deployment.xml.parser.XMLExceptionHandler.fatalError(XMLExceptionHandler.java:34) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:180) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:441) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368) at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1436) at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanPIData(XMLScanner.java:723) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanPIData(XMLDocumentFragmentScannerImpl.java:1018) at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanPI(XMLScanner.java:691) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:912) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213) at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649) at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceXML(PersistenceUnitProcessor.java:655) ... 9 more C:\Users\hp\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 0 seconds)
Versuchen mit 'Persistence.createEntityManagerFactory ("persistencia");', müssen Sie die richtige Persistenzeinheit Namen angeben. –