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

» JWorld@TW » Object Relational Mapping » JPA  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded 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
作者 Re:OpenJPA 在 createEntityManagerFactory 錯誤 [Re:Mandrake]
koji

秒速5センチメートル

站長

發文: 8420
積分: 19
於 2010-10-09 10:01 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
有其他錯誤訊息嗎?

有個可能是相關的jar沒在classpath下

koji


reply to postreply to post
JCConf Taiwan 2015 開始售票了!!
Facebook上的TWJUG社團,歡迎加入
作者 Re:OpenJPA 在 createEntityManagerFactory 錯誤 [Re:koji]
Mandrake





發文: 7
積分: 0
於 2010-10-11 14:59 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
不知道現在出現這個訊息有比較好嗎?
===============================
65 testJPA INFO [main] openjpa.Runtime - Starting OpenJPA 2.0.1
147 testJPA INFO [main] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.MySQLDictionary".
Exception in thread "main" <openjpa-2.0.1-r422266:989424 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: There were errors initializing your configuration: <openjpa-2.0.1-r422266:989424 fatal user error> org.apache.openjpa.util.UserException: A connection could not be obtained for driver class "com.mysql.jdbc.Driver" and URL "jdbc:mysql://localhost:3306/test/". You may have specified an invalid URL.
  at org.apache.openjpa.jdbc.schema.DataSourceFactory.newConnectException(DataSourceFactory.java:261)
  at org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(DataSourceFactory.java:247)
  at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory(JDBCConfigurationImpl.java:728)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  at org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll(ConfigurationImpl.java:294)
  at org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll(OpenJPAConfigurationImpl.java:1602)
  at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:647)
  at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:206)
  at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:154)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:60)
  at testJPA.main(testJPA.java:27)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user 'root'@'%' to database 'test/'
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
  at java.lang.reflect.Constructor.newInstance(Unknown Source)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
  at com.mysql.jdbc.Util.getInstance(Util.java:384)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
  at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004)
  at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284)
  at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312)
  at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122)
  at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774)
  at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
  at java.lang.reflect.Constructor.newInstance(Unknown Source)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
  at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375)
  at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289)
  at org.apache.openjpa.jdbc.schema.SimpleDriverDataSource.getConnection(SimpleDriverDataSource.java:96)
  at org.apache.openjpa.jdbc.schema.SimpleDriverDataSource.getConnection(SimpleDriverDataSource.java:91)
  at org.apache.openjpa.lib.jdbc.DelegatingDataSource.getConnection(DelegatingDataSource.java:139)
  at org.apache.openjpa.lib.jdbc.DecoratingDataSource.getConnection(DecoratingDataSource.java:112)
  at org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(DataSourceFactory.java:239)
  ... 14 more

  at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:221)
  at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:154)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:60)
  at testJPA.main(testJPA.java:27)
Caused by: java.lang.RuntimeException: There were errors initializing your configuration: <openjpa-2.0.1-r422266:989424 fatal user error> org.apache.openjpa.util.UserException: A connection could not be obtained for driver class "com.mysql.jdbc.Driver" and URL "jdbc:mysql://localhost:3306/test/". You may have specified an invalid URL.
  at org.apache.openjpa.jdbc.schema.DataSourceFactory.newConnectException(DataSourceFactory.java:261)
  at org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(DataSourceFactory.java:247)
  at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory(JDBCConfigurationImpl.java:728)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  at org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll(ConfigurationImpl.java:294)
  at org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll(OpenJPAConfigurationImpl.java:1602)
  at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:647)
  at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:206)
  at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:154)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:60)
  at testJPA.main(testJPA.java:27)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user 'root'@'%' to database 'test/'
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
  at java.lang.reflect.Constructor.newInstance(Unknown Source)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
  at com.mysql.jdbc.Util.getInstance(Util.java:384)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
  at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004)
  at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284)
  at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312)
  at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122)
  at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774)
  at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
  at java.lang.reflect.Constructor.newInstance(Unknown Source)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
  at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375)
  at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289)
  at org.apache.openjpa.jdbc.schema.SimpleDriverDataSource.getConnection(SimpleDriverDataSource.java:96)
  at org.apache.openjpa.jdbc.schema.SimpleDriverDataSource.getConnection(SimpleDriverDataSource.java:91)
  at org.apache.openjpa.lib.jdbc.DelegatingDataSource.getConnection(DelegatingDataSource.java:139)
  at org.apache.openjpa.lib.jdbc.DecoratingDataSource.getConnection(DecoratingDataSource.java:112)
  at org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(DataSourceFactory.java:239)
  ... 14 more

  at org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll(ConfigurationImpl.java:308)
  at org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll(OpenJPAConfigurationImpl.java:1602)
  at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:647)
  at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:206)
  ... 5 more
=========================================


Mandrake edited on 2010-10-11 15:02
reply to postreply to post
作者 Re:OpenJPA 在 createEntityManagerFactory 錯誤 [Re:Mandrake]
pico2k

地球真危險



發文: 177
積分: 0
於 2010-10-11 15:41 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
請先檢查以下二件事:
1.確認你用的MySQL Database裡有test這個資料庫
2.你的root密碼是否正確


reply to postreply to post
作者 Re:OpenJPA 在 createEntityManagerFactory 錯誤 [Re:pico2k]
Mandrake





發文: 7
積分: 0
於 2010-10-11 15: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
的確是我的資料庫連不到
但是現在我可以連到了
出現了下面的訊息
======================
66 testJPA INFO [main] openjpa.Runtime - Starting OpenJPA 2.0.1
149 testJPA INFO [main] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.MySQLDictionary".
Exception in thread "main" <openjpa-2.0.1-r422266:989424 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: There were errors initializing your configuration: <openjpa-2.0.1-r422266:989424 fatal user error> org.apache.openjpa.util.UserException: A connection could not be obtained for driver class "com.mysql.jdbc.Driver" and URL "jdbc:mysql://localhost:3306/test/". You may have specified an invalid URL.
  at org.apache.openjpa.jdbc.schema.DataSourceFactory.newConnectException(DataSourceFactory.java:261)
  at org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(DataSourceFactory.java:247)
  at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory(JDBCConfigurationImpl.java:728)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  at org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll(ConfigurationImpl.java:294)
  at org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll(OpenJPAConfigurationImpl.java:1602)
  at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:647)
  at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:206)
  at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:154)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:60)
  at testJPA.main(testJPA.java:27)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'test/'
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
  at java.lang.reflect.Constructor.newInstance(Unknown Source)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
  at com.mysql.jdbc.Util.getInstance(Util.java:384)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
  at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004)
  at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284)
  at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312)
  at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122)
  at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774)
  at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
  at java.lang.reflect.Constructor.newInstance(Unknown Source)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
  at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375)
  at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289)
  at org.apache.openjpa.jdbc.schema.SimpleDriverDataSource.getConnection(SimpleDriverDataSource.java:96)
  at org.apache.openjpa.jdbc.schema.SimpleDriverDataSource.getConnection(SimpleDriverDataSource.java:91)
  at org.apache.openjpa.lib.jdbc.DelegatingDataSource.getConnection(DelegatingDataSource.java:139)
  at org.apache.openjpa.lib.jdbc.DecoratingDataSource.getConnection(DecoratingDataSource.java:112)
  at org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(DataSourceFactory.java:239)
  ... 14 more

  at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:221)
  at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:154)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:60)
  at testJPA.main(testJPA.java:27)
Caused by: java.lang.RuntimeException: There were errors initializing your configuration: <openjpa-2.0.1-r422266:989424 fatal user error> org.apache.openjpa.util.UserException: A connection could not be obtained for driver class "com.mysql.jdbc.Driver" and URL "jdbc:mysql://localhost:3306/test/". You may have specified an invalid URL.
  at org.apache.openjpa.jdbc.schema.DataSourceFactory.newConnectException(DataSourceFactory.java:261)
  at org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(DataSourceFactory.java:247)
  at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory(JDBCConfigurationImpl.java:728)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  at org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll(ConfigurationImpl.java:294)
  at org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll(OpenJPAConfigurationImpl.java:1602)
  at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:647)
  at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:206)
  at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:154)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:60)
  at testJPA.main(testJPA.java:27)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'test/'
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
  at java.lang.reflect.Constructor.newInstance(Unknown Source)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
  at com.mysql.jdbc.Util.getInstance(Util.java:384)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
  at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004)
  at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284)
  at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312)
  at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122)
  at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774)
  at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
  at java.lang.reflect.Constructor.newInstance(Unknown Source)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
  at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375)
  at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289)
  at org.apache.openjpa.jdbc.schema.SimpleDriverDataSource.getConnection(SimpleDriverDataSource.java:96)
  at org.apache.openjpa.jdbc.schema.SimpleDriverDataSource.getConnection(SimpleDriverDataSource.java:91)
  at org.apache.openjpa.lib.jdbc.DelegatingDataSource.getConnection(DelegatingDataSource.java:139)
  at org.apache.openjpa.lib.jdbc.DecoratingDataSource.getConnection(DecoratingDataSource.java:112)
  at org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(DataSourceFactory.java:239)
  ... 14 more

  at org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll(ConfigurationImpl.java:308)
  at org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll(OpenJPAConfigurationImpl.java:1602)
  at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:647)
  at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:206)
  ... 5 more


reply to postreply to post
作者 Re:OpenJPA 在 createEntityManagerFactory 錯誤 [Re:Mandrake]
pico2k

地球真危險



發文: 177
積分: 0
於 2010-10-11 16:47 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
"test/" 改成 "test"...

reply to postreply to post
作者 Re:OpenJPA 在 createEntityManagerFactory 錯誤 [Re:pico2k]
Mandrake





發文: 7
積分: 0
於 2010-10-11 17:39 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
謝啦,的確是把 test/ 後面這個 / 拿掉就過了
不過又出現下面的訊息
===============================
71 testJPA INFO [main] openjpa.Runtime - Starting OpenJPA 2.0.1
160 testJPA INFO [main] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.MySQLDictionary".
Exception in thread "main" <openjpa-2.0.1-r422266:989424 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: This configuration disallows runtime optimization, but the following listed types were not enhanced at build time or at class load time with a javaagent: "
TPolloption
Animal
TTopic".
  at org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(ManagedClassSubclasser.java:116)
  at org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(AbstractBrokerFactory.java:317)
  at org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:241)
  at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:215)
  at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:154)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:60)
  at testJPA.main(testJPA.java:27)
=======================================
似乎每個 class 都要 enhance
請問該怎麼 enhance 呢?
因為我每次都失敗 >"<


reply to postreply to post
作者 Re:OpenJPA 在 createEntityManagerFactory 錯誤 [Re:Mandrake]
koji

秒速5センチメートル

站長

發文: 8420
積分: 19
於 2010-10-11 18:40 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
http://webspherepersistence.blogspot.com/2009/02/openjpa-enhancement.html

參考看看?

koji


reply to postreply to post
JCConf Taiwan 2015 開始售票了!!
Facebook上的TWJUG社團,歡迎加入
作者 Re:OpenJPA 在 createEntityManagerFactory 錯誤 [Re:koji]
Mandrake





發文: 7
積分: 0
於 2010-10-12 13:58 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
現在變成下面訊息
=======================
Exception in thread "main" java.lang.NoSuchMethodError: javax/persistence/spi/PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
  at org.apache.openjpa.persistence.PersistenceUnitInfoImpl.toOpenJPAProperties(PersistenceUnitInfoImpl.java:457)
  at org.apache.openjpa.persistence.PersistenceUnitInfoImpl.toOpenJPAProperties(PersistenceUnitInfoImpl.java:339)
  at org.apache.openjpa.persistence.PersistenceProductDerivation.load(PersistenceProductDerivation.java:536)
  at org.apache.openjpa.persistence.PersistenceProductDerivation.load(PersistenceProductDerivation.java:335)
  at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:89)
  at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:154)
  at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:65)
  at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
  at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
  at testJPA.main(testJPA.java:13)
===============================================


reply to postreply to post
作者 Re:OpenJPA 在 createEntityManagerFactory 錯誤 [Re:Mandrake]
koji

秒速5センチメートル

站長

發文: 8420
積分: 19
於 2010-10-12 17:44 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
全文檢索一下 NoSuchMethodError?

koji


reply to postreply to post
JCConf Taiwan 2015 開始售票了!!
Facebook上的TWJUG社團,歡迎加入
作者 Re:OpenJPA 在 createEntityManagerFactory 錯誤 [Re:koji]
Mandrake





發文: 7
積分: 0
於 2010-10-18 11:05 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
謝啦,小弟我已經解決了 NoSuchMethodError 的錯誤了
換一個 jar 檔就 ok 了
不過現在卻出現另外一個錯誤 Disapproved
===================================
IWAV0055I Java Bean testJPA started with the main method
538 jpa INFO [main] openjpa.Runtime - Starting OpenJPA 2.0.1
700 jpa INFO [main] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.MySQLDictionary".
===========================================
請問這又是甚麼問題呢?


reply to postreply to post
作者 Re:OpenJPA 在 createEntityManagerFactory 錯誤 [Re:Mandrake]
koji

秒速5センチメートル

站長

發文: 8420
積分: 19
於 2010-10-18 14:04 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
他有說這是錯誤嗎?
info == error?

koji


reply to postreply to post
JCConf Taiwan 2015 開始售票了!!
Facebook上的TWJUG社團,歡迎加入
作者 Re:OpenJPA 在 createEntityManagerFactory 錯誤 [Re:Mandrake]
BaileyCheng





發文: 11
積分: 0
於 2010-10-18 17:43 user profilesend a private message to usersend email to BaileyChengreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
看起來應該沒有甚麼問題才是

他沒在console印出 id ,name等資料? 你table裡有資料嗎?


reply to postreply to post
國票證券資訊部
Bailey Cheng
E-mail: fangchen.cheng@gmail.com
作者 Re:OpenJPA 在 createEntityManagerFactory 錯誤 [Re:BaileyCheng]
Mandrake





發文: 7
積分: 0
於 2010-10-19 11:30 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
我是跑到
EntityManagerFactory factory = Persistence.createEntityManagerFactory("testJPA");
就出現了,程式就終止了
IWAV0055I Java Bean testJPA started with the main method
172 jpa INFO [main] openjpa.Runtime - Starting OpenJPA 2.0.1
322 jpa INFO [main] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.MySQLDictionary".


reply to postreply to post
作者 Re:OpenJPA 在 createEntityManagerFactory 錯誤 [Re:Mandrake]
koji

秒速5センチメートル

站長

發文: 8420
積分: 19
於 2010-10-19 14:01 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
表示你程式有問題吧?
外加你catch exception竟然沒有處理
當然看不出來哪裡錯

koji


reply to postreply to post
JCConf Taiwan 2015 開始售票了!!
Facebook上的TWJUG社團,歡迎加入
作者 Re:OpenJPA 在 createEntityManagerFactory 錯誤 [Re:Mandrake]
BaileyCheng





發文: 11
積分: 0
於 2010-10-19 19:12 user profilesend a private message to usersend email to BaileyChengreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
也許是你 animal class有錯? 把你有引入的library 和 animal class 都列出來好了...

reply to postreply to post
國票證券資訊部
Bailey Cheng
E-mail: fangchen.cheng@gmail.com
» JWorld@TW »  Object Relational Mapping » JPA

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

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8