我跟着
https://glassfish.java.net/javaee5/persistence/persistence-example.html
在Java SE环境中测试JPA.
在Eclipse中,我:
>创建了一个新的JPA(2.1)项目;
>在options-> JPA->持久类管理中,我选择了“自动发现带注释的类”,而不是“必须在persistence.xml中列出带注释的类”.
我成功导入了zip文件(Client.java Customer.java Order.java)中的树Java类,并修改了persistence.xml文件以满足我的需要.但是在尝试执行main时我得到以下错误.
[EL Info]: 2013-10-18 17:37:54.749--ServerSession(263489307)--EclipseLink,version: Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5
[EL Info]: connection: 2013-10-18 17:37:55.34--ServerSession(263489307)--file:/home/caterpillar/workspace/JPA_Java_SE/build/classes/_JPA_Java_SE login successful
[EL Warning]: Metamodel: 2013-10-18 17:37:55.359--The collection of Metamodel types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either
persistence.xml中
MysqL://localhost:3306/test?useUnicode=true&characterEncoding=utf8"/>
MysqL.jdbc.Driver"/>
项目目录树:
$tree
.
├── build
│ └── classes
│ ├── client
│ │ └── Client.class
│ ├── entity
│ │ ├── Customer.class
│ │ └── Order.class
│ └── Meta-INF
│ └── persistence.xml
├── sql
│ ├── tables_derby.sql
│ └── tables_oracle.sql
└── src
├── client
│ └── Client.java
├── entity
│ ├── Customer.java
│ └── Order.java
└── Meta-INF
└── persistence.xml
10 directories,10 files
所有clases代码与http://glassfish.dev.java.net/javaee5/persistence/JPASE.zip的avaible示例文件相同
最佳答案
persistence.xml中缺少下一行:
原文链接:https://www.f2er.com/mysql/433687.html
此行的位置如下例所示: