【发布时间】:2015-02-20 17:13:27
【问题描述】:
我正在使用 Intellij 社区版学习 JPA。我读过它可以与这个 Intellij 版本一起使用。
我已经使用 pgAdmin 在 localhost 上创建了我的数据库。我已将外部 jars 添加到我的项目中(JDBC Postresql 驱动程序 + javax.presistance)。我已经(手动)使用 persistence.xml 文件制作了 META-INF 文件夹:
<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="testname" transaction-type="RESOURCE_LOCAL">
<class>presistencetest.Car</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://host:localhost:5432/databasename"/>
<property name="javax.persistence.jdbc.user" value="postgresql"/>
<property name="javax.persistence.jdbc.password" value="password"/>
</properties>
</persistence-unit>
当我尝试启动简单测试(部分代码)时:
public static void main(String[] args) {
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("testname");
EntityManager em = emf.createEntityManager();
我收到错误消息:
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named testname
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:84)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at presistencetest.Car.main(Car.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
【问题讨论】:
-
你能发布你的文件夹结构吗?
标签: java postgresql jpa intellij-idea