我的文件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 的初学者