java - 获取数据库信息时出错?在 EclipseLink 中与 Oracle

标签 java oracle jpa eclipselink

我正在使用 eclipselink 制作一个小型应用程序。当我尝试将数据插入数据库时​​,它抛出异常。

使用的技术有:

IDE:Eclipse ORM:EclipseLink 平台:JAVA 数据库:Oracle

以前我使用 MySql 工作得很好。当我更改数据库时,出现了问题。

下面是persistance.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence  http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="OracleDemo" transaction-type="RESOURCE_LOCAL">
    <class>com.demo.UserDetails</class>
<properties>

        <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:XE" />
        <property name="javax.persistence.jdbc.user" value="testjpa" />
        <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver" />
        <property name="javax.persistence.jdbc.password" value="testjpa"/>

        <property name="eclipselink.ddl-generation" value="create-tables" />            
        <property name="eclipselink.create-ddl-jdbc-file-name"  value="createDDL_ddlGeneration.jdbc" />
        <property name="eclipselink.drop-ddl-jdbc-file-name" value="dropDDL_ddlGeneration.jdbc" />
        <property name="eclipselink.ddl-generation.output-mode" value="both" />

    </properties>
</persistence-unit>
</persistence>

我的InsertData.java

public class InsertData {

public static void main(String[] args) {

    UserDetails userDetails = new UserDetails();
    userDetails.setName("prabha");
    userDetails.setCity("SKLM");

    EntityManager entityManager = EntityManagerUtil.getEmf().createEntityManager();
    try {
        EntityTransaction entr = entityManager.getTransaction();
        entr.begin();

        entityManager.persist(userDetails);

        entr.commit();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        entityManager.close();
    }
}
}

异常

[EL Info]: 2014-03-17 15:15:32.603--ServerSession(799611093)--EclipseLink, version: Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5
[EL Severe]: ejb: 2014-03-17 15:15:32.801--ServerSession(799611093)--Exception [EclipseLink-4019] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Error while obtaining information about the database. Refer to  the nested exception for more details.
 Exception in thread "main" javax.persistence.PersistenceException: Exception  [EclipseLink-4019] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5):  org.eclipse.persistence.exceptions.DatabaseException
 Exception Description: Error while obtaining information about the database. Refer to the nested exception for more details.
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:766)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:304)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:336)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:302)
at com.demo.ReadData.main(ReadData.java:14)
 Caused by: Exception [EclipseLink-4019] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
  Exception Description: Error while obtaining information about the database. Refer to the nested exception for more details.
at org.eclipse.persistence.exceptions.DatabaseException.errorRetrieveDbMetadataThroughJDBCConnection(DatabaseException.java:368)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasource(DatabaseSessionImpl.java:226)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:741)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:239)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:685)
... 5 more

最佳答案

JDK 1.6结合的官方JAR文件是ojdbc6.jar。当您与Oracle11g一起使用而不是使用ojdbc14.jar时,请使用ojdbc6.jar

关于java - 获取数据库信息时出错?在 EclipseLink 中与 Oracle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22450566/

相关文章:

java - 为什么 $expand 在我的 JPA/Olingo 项目中不能正常工作

spring - 不能使用 Kotlin 配置带有抽象类的 Spring JPA 实体

java - 清除 Runnable 对象的 ArrayList 时会发生什么?

java - Java中的HttpRequest : Always goes to 404

java - ANDROID没有R.java

c# - 使用 ODP.NET 的第一次查询总是很慢

java - 使用 LWJGL 小程序访问资源

sql - 如何在 oracle 数据库中编写参数化查询

mysql - 对于小型 Web 项目,MySQL 或 Oracle 哪个更快?

java - 使用 @OneToMany 或 @ManyToMany 定位未映射的类 : kg. aladin.jdbc.Student.books[kg.aladin.jdbc.Book]