2016-05-05 9 views
-1

私はJPAを初めて使いました。javax.persistence.PersistenceException:EntryManagerの永続プロバイダ(Eclipselink_JPA)がありません

私はいくつかのテストを行うためにnetbeansでエンタープライズプロジェクトを作成しました。ウィザードでこの永続ユニットを作成しました。私はそれを適切に動作JNDI接続を追加し、それがすでにテストされています:

<?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> 

その後、私はこれがどのように動作するかを確認するためにいくつかのテスト変数とサンプルエンティティを作成しました:

@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 

続いて、作ってみましたサービスCreateEntity1それを試してみると、それを呼び出すことによって、DB上に新しい要素を作成しようとする:

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(); 
    } 
} 

...しかし、それは動作しません。次のエラーが表示されます。

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named Eclipselink_JPA at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54) at service.CreateEntity1.main(CreateEntity1.java:22) C:\Users\hp\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 0 seconds)

私は間違っていますか?

EDIT:永続性プロバイダの名前を適切なものに変更しましたが、今は重大なエラーが発生しています。

EDIT 2:すべてをHibernate型に変更しました。まだ巨大なエラーが発生しています:

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)

+2

'Persistence.createEntityManagerFactory( "persistencia")で試してみてくださいを;'、あなたは正しい永続性ユニット名を指定する必要があります。 –

答えて

1

あなたはこのようにそれを追加する<provider>...試して見逃している:

<?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"> 
    <provider>org.hibernate.ejb.HibernatePersistence</provider> 
    ... 
+0

これは失敗し続けます。今すぐ行うつもりの編集を確認してください – Zerok

+0

CLASSPATHに1つしかない場合はプロバイダを指定する必要はありません –

関連する問題