2013-08-29 1 views
1

Im пытается сделать Hibernate работать с моим проектом Gradle, но все, что я получил это Исключение в потоке «основного» javax.persistence.PersistenceException: Нет провайдер ПостоянствоИспользование Hibernate с Gradle - не поставщик сохранения для EntityManager не назвал

for EntityManager named manago 
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69) 
    at jpa.EntityManagerFactory.reinit(EntityManagerFactory.java:69) 
    at jpa.EntityManagerFactory.<init>(EntityManagerFactory.java:61) 
    at jpa.EntityManagerFactory.<init>(EntityManagerFactory.java:56) 
    at jpa.EntityManagerFactory.getInstance(EntityManagerFactory.java:43) 
    at main.Main.main(Main.java:32) 
:run FAILED 

мой файл build.gradle:

apply plugin: 'application' 
apply plugin: 'java' 
apply plugin: 'war' 
mainClassName = "main.Main" 
sourceSets.main.output.resourcesDir = sourceSets.main.output.classesDir 
sourceCompatibility = '1.6' 
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' 

if (!hasProperty('mainClass')) { 
    ext.mainClass = 'main.Main' 
} 

repositories { 
    mavenCentral() 
} 

dependencies { 
    compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final' 
    compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '3.6.7.Final' 
    compile 'postgresql:postgresql:9.1-901-1.jdbc4' 
    compile "javax.ws.rs:jsr311-api:1.1.1" 
    compile 'com.sun.jersey:jersey-server:1.13' 
    compile 'com.sun.jersey:jersey-core:1.13' 
    compile 'com.sun.jersey:jersey-servlet:1.13' 
    testCompile group: 'junit', name: 'junit', version: '4.10' 
    runtime group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final' 
    runtime group: 'org.hibernate', name: 'hibernate-entitymanager', version: '3.6.7.Final' 
} 

persistence.xml файл в каталоге/SRC/META-INF:

<?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="WebSISMSPUpgsql" transaction-type="RESOURCE_LOCAL"> 
    <provider>org.hibernate.ejb.HibernatePersistence</provider> 
    <class>jpa.Routes</class> 
    <exclude-unlisted-classes>false</exclude-unlisted-classes> 
    <properties> 
     <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/> 
     <property name="hibernate.connection.username" value="postgres"/> 
     <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/> 
     <property name="hibernate.connection.password" value="postgres"/> 
     <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/postgres"/> 
     <property name="hibernate.ejb.event.post-insert" value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener"/> 
     <property name="hibernate.ejb.event.post-update" value="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener"/> 
     <property name="hibernate.ejb.event.post-delete" value="org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener"/> 
     <property name="hibernate.ejb.event.pre-collection-update" value="org.hibernate.envers.event.AuditEventListener"/> 
     <property name="hibernate.ejb.event.pre-collection-remove" value="org.hibernate.envers.event.AuditEventListener"/> 
     <property name="hibernate.ejb.event.post-collection-recreate" value="org.hibernate.envers.event.AuditEventListener"/> 
    </properties> 
</persistence-unit> 
</persistence> 

Основной класс:

package main; 

import javax.persistence.EntityManager; 
import javax.persistence.EntityManagerFactory; 
import java.sql.Driver; 
import java.sql.DriverManager; 
import java.sql.Connection; 
import java.sql.SQLException; 
import java.util.Date; 
import javax.persistence.Persistence; 
import jpa.Routes; 
import org.hibernate.Session; 


public class Main { 
    public static void main(String[] args) { 
       EntityManagerFactory emf = Persistence.createEntityManagerFactory("manago"); 
    } 
} 

Что я должен сделать, чтобы, наконец, получить его на работу?

ответ

0

Ваша настойчивость-единица - достаточно четко - назван WebSISMSPUpgsql в вашем persistence.xml и не manago. Просто измените Main.main на

public static void main(String[] args) { 
EntityManagerFactory emf = \ 
    Persistence.createEntityManagerFactory("WebSISMSPUpgsql"); 
} 

или измените название устройства в файле persistence.xml.

+0

Я изменил его, но он не помог – pawel

+0

Что нового в стеке, сообщение об ошибке? Я попробовал ваш пример вместе с моим советом, и он работал, как и было обещано. – whaefelinger

+0

@pawel Вот где мой persistence.xml: $ find. -name persistence.xml => _./build/classes/main/META-INF/persistence.xml ./src/main/resources/META-INF/persistence.xml_ – whaefelinger

Смежные вопросы