私のファイルsrc / main / resources / META-INF / persistence.xml
は次のとおりです。
<?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="todo" transaction-type="RESOURCE_LOCAL">
<class>com.testJPA.classes.Voiture</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:todos" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
<property name="openjpa.RuntimeUnenhancedClasses" value="supported"/>
</properties>
</persistence-unit>
私の主なクラスは次のとおりです。
package com.testJPA.classes;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print("Hello");
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("todo");
EntityManager em = emf.createEntityManager();
for (int i = 0; i < 10; i++) {
Voiture car = new Voiture("a", "b", "c");
em.persist(car);
}
em.getTransaction().commit();
// Find the number of Point objects in the database:
Query q1 = em.createQuery("SELECT COUNT(v) FROM Voiture v");
System.out.println("Le nombre d'enregistrement: "
+ q1.getSingleResult());
}
}
私のクラス「Voiture」は次のとおりです。
package com.testJPA.classes;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Voiture {
@Id private String matricule;
String position;
String vitesse;
public Voiture(String matricule, String position, String vitesse) {
this.matricule = matricule;
this.position = position;
this.vitesse = vitesse;
}
public Voiture() {
this.matricule = "";
this.position = "";
this.vitesse = "";
}
public String getMatricule() {
return matricule;
}
public void setMatricule(String matricule) {
this.matricule = matricule;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public String getVitesse() {
return vitesse;
}
public void setVitesse(String vitesse) {
this.vitesse = vitesse;
}
}
次の発見された実装を試した後、「todo」に使用できる永続化プロバイダーがありません
申し訳ありませんが、私はJava EEの初心者です