JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Object Relational Mapping » JPA  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
作者 OpenJPA 在 createEntityManagerFactory 錯誤
Mandrake





發文: 7
積分: 0
於 2010-10-08 16:53 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
小弟我在 eclipse 的 Project
新增一個JPA Project
可是卻發生了下面問題
=====================
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named testJPA
  at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
  at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
  at testJPA.main(testJPA.java:11)
========================
persistence.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
  <persistence-unit name="testJPA" transaction-type="RESOURCE_LOCAL">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <class>Animal</class>
    <properties>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/test/"/>
      <property name="javax.persistence.jdbc.user" value="root"/>
      <property name="javax.persistence.jdbc.password" value="root"/>
    </properties>
  </persistence-unit>
</persistence>

testJPA.java
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
import javax.persistence.*;
import java.util.*;
 
public class testJPA {
 
  /**
   * @param args
   */
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    EntityManagerFactory factory = Persistence.createEntityManagerFactory("testJPA");
    EntityManager em = factory.createEntityManager();
    try {
      Query query = em.createQuery("select a from Aminal a");
      List list = query.getResultList();
      Iterator iterator = list.iterator();
      while (iterator.hasNext()) {
        Animal animal = (Animal) iterator.next();
        System.out.println("id:" + animal.getId());
        System.out.println("name:" + animal.getName());
      }
 
    } catch (Exception e) {
      // TODO: handle exception
    } finally {
      em.close();
    }
  }
 
}


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
1717 OpenJPA 在 createEntityManagerFactory 錯誤 Mandrake 2159 2010-10-08 16:53
1504 Re:OpenJPA 在 createEntityManagerFactory 錯誤 koji 46 2010-10-09 10:01
1472 Re:OpenJPA 在 createEntityManagerFactory 錯誤 Mandrake 9454 2010-10-11 14:59
1420 Re:OpenJPA 在 createEntityManagerFactory 錯誤 pico2k 60 2010-10-11 15:41
1446 Re:OpenJPA 在 createEntityManagerFactory 錯誤 Mandrake 9259 2010-10-11 15:53
1423 Re:OpenJPA 在 createEntityManagerFactory 錯誤 pico2k 20 2010-10-11 16:47
1534 Re:OpenJPA 在 createEntityManagerFactory 錯誤 Mandrake 1568 2010-10-11 17:39
1412 Re:OpenJPA 在 createEntityManagerFactory 錯誤 koji 92 2010-10-11 18:40
1448 Re:OpenJPA 在 createEntityManagerFactory 錯誤 Mandrake 1243 2010-10-12 13:58
1383 Re:OpenJPA 在 createEntityManagerFactory 錯誤 koji 35 2010-10-12 17:44
1411 Re:OpenJPA 在 createEntityManagerFactory 錯誤 Mandrake 404 2010-10-18 11:05
1345 Re:OpenJPA 在 createEntityManagerFactory 錯誤 koji 33 2010-10-18 14:04
1379 Re:OpenJPA 在 createEntityManagerFactory 錯誤 BaileyCheng 59 2010-10-18 17:43
1411 Re:OpenJPA 在 createEntityManagerFactory 錯誤 Mandrake 339 2010-10-19 11:30
1320 Re:OpenJPA 在 createEntityManagerFactory 錯誤 koji 55 2010-10-19 14:01
1534 Re:OpenJPA 在 createEntityManagerFactory 錯誤 BaileyCheng 64 2010-10-19 19:12
» JWorld@TW »  Object Relational Mapping » JPA

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8