J'essaye de suivre un tutoriel sur JPA :
http://jl2tho.blogspot.com/2007/08/t...jb-entity.html
Mais je bloque. Je n'arrive pas à instancier EntityManagerFactory.
J'ai suivi le tutoriel à la lettre. En particulier, j'ai créer le fichier persistence.xml dans un répertoire META-INF que j'ai placé à la racine de mon projet. Voici mon fichier persistence.xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3EntityManagerFactory emf = Persistence.createEntityManagerFactory("sample"); //null EntityManager em = emf.createEntityManager();
Je pense que l'erreur provient du fait que le fichier persistence.xml n'est pas lu. Est-ce qu'il ne faut pas spécifier quelque part l'emplacement de ce fichier ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 <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_1_0.xsd" version="1.0"> <persistence-unit name="sample" transaction-type="RESOURCE_LOCAL"> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" /> <property name="hibernate.hbm2ddl.auto" value="create" /> <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" /> <property name="hibernate.connection.username" value="sa" /> <property name="hibernate.connection.password" value="" /> <property name="hibernate.connection.url" value="jdbc:hsqldb:hsql://localhost/jpatest" /> <property name="hibernate.show_sql" value="true" /> </properties> </persistence-unit> </persistence>








Répondre avec citation
Partager