Konfiguracja JPA - błąd

0

Witam! Mam problem z JPA, przerabiam aktualnie tutorial jednego z użytowników forum no i przy próbie odpalenia programu wywala mi parę problemów.Wydruk z konsolki :

maj 17, 2015 832 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
maj 17, 2015 832 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
maj 17, 2015 832 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
maj 17, 2015 832 PM org.hibernate.jpa.boot.internal.PersistenceXmlParser doResolve
INFO: HHH000318: Could not find any META-INF/persistence.xml file in the classpath
maj 17, 2015 832 PM org.hibernate.jpa.boot.internal.PersistenceXmlParser doResolve
INFO: HHH000318: Could not find any META-INF/persistence.xml file in the classpath
maj 17, 2015 832 PM org.hibernate.jpa.boot.internal.PersistenceXmlParser doResolve
INFO: HHH000318: Could not find any META-INF/persistence.xml file in the classpath
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named MyDatabase
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at info.jk.Main.main(Main.java:12)

persistance.xml -

 <persistence 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"
	version="2.0">

	<persistence-unit name="MyDatabase" transaction-type="RESOURCE_LOCAL">
		<provider>org.hibernate.jpa.HibernatePersistence</provider>

		<properties>
			<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver.class" />
			<property name="javax.persistence.jdbc.user" value="tutorial" />
			<property name="javax.persistence.jdbc.password" value="1234" />
			<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/mojabaza" />
			<property name="hibernate.dialect" value="org.hibernate.dialect.MYSQL5Dialect" />
			<property name="hibernate.max_fetch_depth" value="3" />
			<property name="hibernate.hbm2ddl.auto" value="create" />




		</properties>
	</persistence-unit>
</persistence>
 import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class Main {

	public static void main(String[] args) {
	
	EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("MyDatabase");
	EntityManager entityManager = entityManagerFactory.createEntityManager();

	Employee employee = new Employee();
	employee.setId(1L);
	employee.setFirstName("Jan");
	employee.setLastName("Kowalski");
	employee.setSalary(3333.3);
	
	entityManager.getTransaction().begin();
	entityManager.persist(employee);
	entityManager.getTransaction().commit();

	
	entityManager.close();
	entityManagerFactory.close();
	
	
	}

}

Folder META-INF znajduje się bezpośrednio pod src.

0

Moim zdaniem ścieżka do persistance.xml jest nieprawidłowa. Patrząc folderowo spróbuj ustawić na:

src/main/resources/META-INF/persistence.xml

Powinien zobaczyć. Jak foldery nie istnieją to je utwórz.

0

Niestety dalej nie działa.

0

Jak masz wciąż ten sam błąd to usuń co masz i spróbuj utworzyć persistence.xml przez IDE tzn. w NetBeans na projekcie:
New / Persistance Unit. U mnie to zawsze działało bez problemów.

0

No dokładnie tak, błąd ten sam. Ok, spróbuje w netbeans bo teraz robiłem to w eclipse

0

masz plik persistance.xml a nie masz pliku persistence.xml

0

Rzeczywiście miałem tam literówkę, poprawilem i został teraz jeden WARN: HHH 015016.

1 użytkowników online, w tym zalogowanych: 0, gości: 1