JPA/EclipseLink不返回结果 [英] JPA/EclipseLink Returning No Results

查看:67
本文介绍了JPA/EclipseLink不返回结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java和JPA的新手.我试图连接到数据库并从表中返回一些结果,但是当我运行查询时,即使表有超过100,000行,结果还是得到一个空列表.

I am new to Java and JPA. I am trying to connect to a database and return some results from a table, but when I run the query, I get an empty list as a result even though the table has over 100,000 rows.

这是我的persistence.xml:

Here is my persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence 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_1_0.xsd"
version="1.0">

<persistence-unit name="tDocc-PG" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
     <!--<exclude-unlisted-classes>false</exclude-unlisted-classes>-->
    <properties>
        <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
        <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://172.16.100.111/tDoccTEST" />
        <property name="javax.persistence.jdbc.user" value="REMOVED" />
        <property name="javax.persistence.jdbc.password" value="REMOVED" />
    </properties>
</persistence-unit>    

这是我的实体:

package com.tdocc.core.entities;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name="Documents")
public class Document {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private int documentID;
private String name;
private int folderID;
private String hash;
private String link;
private String fileType;
private long fileSize;
private String owner;
private String modifier;
private String description;
private String referenceNumber;
@Temporal(TemporalType.DATE)
private Date dateAdded;
@Temporal(TemporalType.DATE)
private Date dateModified;
private boolean readOnly;
private int superseded;
private int category;
private String ocr;
private boolean deleted;

public int getDocumentID() {
    return documentID;
}
public void setDocumentID(int documentID) {
    this.documentID = documentID;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public String getOwner() {
    return owner;
}
public void setOwner(String owner) {
    this.owner = owner;
}
}

这是我用来运行查询的测试类:

And this is my test class that I am using to run the Query:

package com.tdocc.core.tests;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
import com.tdocc.core.entities.Document;

import junit.framework.TestCase;

public class DocumentTest extends TestCase {
public void testConnection() {
    EntityManagerFactory factory = Persistence.createEntityManagerFactory("tDocc-PG");
    EntityManager em = factory.createEntityManager();
    Query q = em.createQuery("SELECT d FROM Document d");
    q.setMaxResults(20);

    List<Document> documents = q.getResultList();
    for (Document doc : documents) {
        System.out.println(doc.getName());
    }

    assertTrue(true);
}
}

有什么想法吗?谢谢.

推荐答案

罗斯,

我们在6月23日发布的EclipseLink 2.1(Helios)中增强了元数据处理,以解决某些区分大小写的问题.

We have enhanced our metadata processing in EclipseLink 2.1 (Helios) released June 23rd to address some case sensitivity issues.

如果您指定表名,它将在生成的SQL中使用大小写.

If you specify the table name as you have it will use your casing in generated SQL.

如果在生成的SQL中需要引号,则可以将表名指定为:

If you require quotes in the generated SQL you can specify the table name as:

@Table(name ="\" Documents \")

@Table(name="\"Documents\"")

道格

这篇关于JPA/EclipseLink不返回结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆