BDD Derby embarquée Java SE + Eclipselink
Bonjour,
j'ai une magnifique erreur lorsque j’exécute un bout de code de test,
Code:
[EL Warning]: metamodel: 2013-07-25 11:22:33.953--The collection of metamodel types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element
J'ai tenté d'ajouter a mon persitence.xml la dernière balise sans aucun succès.
et j'ai une stack error lorsque j’exécute une requête sur mon entité.
quelqu'un aurait une idée du pourquoi ?
voila mon persitence.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <?xml version="1.0" encoding="UTF-8"?>
<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" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="CWFSE" transaction-type="RESOURCE_LOCAL">
<class>com.cwfse.model.entities.messagesErreur</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url"
value="jdbc:derby:CWFSE;create=true" />
<property name="javax.persistence.jdbc.user" value="test" />
<property name="javax.persistence.jdbc.password" value="test" />
<!-- EclipseLink should create the database schema automatically -->
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode"
value="database" />
</properties>
</persistence-unit>
</persistence> |
mon entité
Code:
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| package com.cwfse.model.entities;
import java.io.Serializable;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
public class MessagesErreur implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String libelle;
private String description;
public String getLibelle() {
return libelle;
}
public void setLibelle(String libelle) {
this.libelle = libelle;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public String toString() {
return "messagesErreur [libelle=" + libelle + ", description=" + description
+ "]";
}
} |
et mon appel dans un main
Code:
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 29 30
|
private static final String PERSISTENCE_UNIT_NAME = "CWFSE";
private static EntityManagerFactory factory;
String userHomeDir = System.getProperty("user.dir");
String systemDir = userHomeDir + "/CWFSE";
// Set the db system directory.
System.setProperty("derby.system.home", systemDir);
System.out.println(systemDir);
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
em.getTransaction().begin();
MessagesErreur todo = new MessagesErreur();
todo.setLibelle("This is a test");
todo.setDescription("This is a test");
em.persist(todo);
em.getTransaction().commit();
Query q = em.createQuery("select t from messagesErreur t");
List<MessagesErreur> todoList = q.getResultList();
for (MessagesErreur msg : todoList) {
System.out.println(msg);
}
em.close(); |