0
有人來知道在哪裏可以是問題 - 我收到異常沒有持久性提供的EntityManager中的IntelliJ
找不到任何META-INF/persistence.xml文件在classpath
我使用的IntelliJ和與Hibernate
H2數據庫連接有我的課:
持久性:
<?xml version="1.0" encoding="UTF-8"?>
<!--suppress DeprecatedClassUsageInspection -->
<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="StudentPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>model.StudentInfo</class>
<properties>
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.connection.driver_class" value="org.h2.Driver" />
<property name="hibernate.connection.url" value="jdbc:h2:~/JPA_App" />
<property name="hibernate.connection.user" value="sa" />
<property name="hibernate.connection.password" value="" />
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.temp.use_jdbc_metadata_defaults"
value="false" />
</properties>
</persistence-unit>
</persistence>
實體類:
package model;
import javax.persistence.*;
@Entity
@Table(name = "Student")
public class StudentInfo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name = "name", length = 30, nullable = false)
private String name;
@Column(name = "lastname", length = 30, nullable = false)
private String lastname;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
}
和Main類
package model;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class AddStudent {
public static void main(String[] args) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("StudentPU");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
StudentInfo student = new StudentInfo();
student.setId(0);
student.setName("John");
student.setLastname("Doe");
em.persist(student);
em.getTransaction().commit();
em.close();
emf.close();
}
}
在Eclipse這個簡單源的作品,但在我的IntelliJ收到此異常。 我會很感激任何想法來解決這個錯誤。
最好的問候,
D. Balamjiev