【发布时间】:2014-09-19 00:28:46
【问题描述】:
我正在尝试在 Eclipse 中配置示例 JPA 应用程序,并将其部署到 TomEE+。数据源是容器管理的。尝试创建 EntityManager 时,我不断看到以下错误:
持久性提供程序正在尝试使用 persistence.xml 文件中的属性来解析数据源。 Java 数据库连接 (JDBC) 驱动程序或数据源类名称必须在 openjpa.ConnectionDriverName 或 javax.persistence.jdbc.driver 属性中指定。配置中提供了以下属性:“org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl@414793b4”。
知道这个配置有什么问题吗?
下面是代码。
tomee.xml
<tomee>
<Resource id="jdbc/MyAppDS" type="DataSource">
JdbcDriver com.microsoft.sqlserver.jdbc.SQLServerDriver
JdbcUrl jdbc:sqlserver://localhost:1433/db_dev
UserName user
Password password
JtaManaged true
DefaultAutoCommit false
</Resource>
</tomee>
persistence.xml
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.0">
<persistence-unit name="Simplest" transaction-type="JTA">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>jdbc/MyAppDS</jta-data-source>
<class>social.Media</class>
</persistence-unit>
</persistence>
Media.java
package social;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "media")
public class Media {
@Id
@Column(name = "id")
private String id;
private String description;
private String title;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
Controller.java
package social;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/hello")
public class Controller {
@Inject private Media media;
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayHello() {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("Simplest");
EntityManager em = emf.createEntityManager(); // exception reported on this line
.
.
.
return media.getDescription();
}
}
【问题讨论】:
标签: java openjpa openejb apache-tomee