Hibernate和带Java的Postgresql 9.0

Hibernate和带Java的Postgresql 9.0,hibernate,postgresql,jpa,Hibernate,Postgresql,Jpa,我有一个应用程序,它使用hibernat创建的实体收集一部分数据,其余数据通过简单的jdbc数据库连接和sql语句收集。节约也是一样的。我最近将数据库从Postgresql 8.4升级到Postgresql 9.0,并注意到与实体一起收集的所有数据不再显示。我可以用实体保存数据,但不能显示相同的数据 我升级到Hibernate 3.6.2,没有任何修复,我还从postgresql 9.0-801更新到了最新的JDBC3驱动程序。这两个问题都没有解决 这里是一个可以工作的实体。自从数据库升级后,我

我有一个应用程序,它使用hibernat创建的实体收集一部分数据,其余数据通过简单的jdbc数据库连接和sql语句收集。节约也是一样的。我最近将数据库从Postgresql 8.4升级到Postgresql 9.0,并注意到与实体一起收集的所有数据不再显示。我可以用实体保存数据,但不能显示相同的数据

我升级到Hibernate 3.6.2,没有任何修复,我还从postgresql 9.0-801更新到了最新的JDBC3驱动程序。这两个问题都没有解决

这里是一个可以工作的实体。自从数据库升级后,我没有改变

package com.ajrs.entities;

import java.io.Serializable;
import javax.persistence.*;  
import static javax.persistence.GenerationType.*;

@Entity
@Table(name="lk_note_category")
@NamedQueries({
@NamedQuery(
name="LkNoteCategory.getAll",
        query="SELECT l FROM LkNoteCategory l"
        )
})

public class LkNoteCategory implements Serializable {

@Id
private String category;    
private String description;
private boolean default_category;    

public String getCategory() {
    return category;
}

public void setCategory(String category) {
    this.category = category;
}

public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description;
}

public boolean isDefault_category() {
    return default_category;
}

public void setDefault_category(boolean default_category) {
    this.default_category = default_category;
}
}

因此,我使用以下内容创建note categories对象:

noteCategories = em.createNamedQuery("LkNoteCategory.getAll").getResultList();
加载一个并根据我的netbeans调试器获取所有类别

这是一个不起作用的实体

enter code herepackage com.ajrs.entities;

import java.io.Serializable;
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import static javax.persistence.CascadeType.*;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.*;
import javax.persistence.NamedNativeQuery;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.SequenceGenerator;
import javax.persistence.Transient;

@Entity
@NamedQueries({
@NamedQuery(
name="Note.oldgetByClaimNo",
        query="select n from Note n where n.claimNo = :claim_no order by n.created"
        ),
        @NamedQuery(
name="Note.getByCategoryAndSubcategory",
        query="select n from Note n where n.claimNo = :claim_no and n.category = :category and n.subcategory = :subcategory order by n.created"
        )
})
@NamedNativeQuery(name="Note.getByClaimNo",
query=
    "select claim_no, userid, date, note, category, subcategory, note_id from "+
    "(      select 1 as ord1, extract (epoch from date) as ord2, claim_no, userid, date, note, category, subcategory, note_id "+
    "       from note " +
    "       where claim_no = :claim_no "+
    "       and(subcategory is null or category != 'VI') " +
    "       and date <= (select coalesce(min(date),'1/1/3999') " +
    "                    from note n2 " +
    "                    where n2.claim_no = note.claim_no " +
    "                      and (n2.subcategory is not null " +
    "                           and n2.category = 'VI')" +
    "                          ) "+
    "       union "+
    "       select 2 as ord1, sort_order as ord2, claim_no, userid, date, note, category, subcategory, note_id " +
    "       from(select note.*, sort_order " +
    "                from note inner join lk_note_subcategory using(subcategory) "+
    "                where claim_no = :claim_no "+
    "               and (note.subcategory is not null and " +
    "                        note.category = 'VI') "+
    "               ) as foo " +
    "       union " +
    "       select 3 as ord1, extract (epoch from date) as ord2, claim_no, userid, date, note, category, subcategory, note_id "+
    "       from note " +
    "       where claim_no = :claim_no "+
    "       and(subcategory is null or category != 'VI') " +
    "       and date > (select coalesce(min(date),'1/1/3999') " +
    "                    from note n2 " +
    "                    where n2.claim_no = note.claim_no " +
    "                      and (n2.subcategory is not null " +
    "                           and n2.category = 'VI')" +
    "                          ) "+
    ") as dummy " +
    "order by ord1, ord2"
    , resultClass=Note.class)


    public class Note implements Serializable {
public static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy=SEQUENCE, generator="NOTE_SEQUENCE_GENERATOR")
@SequenceGenerator(name="NOTE_SEQUENCE_GENERATOR", sequenceName="NOTE_NOTE_ID_SEQ")
private int note_id;

private String note;
private String userid;
@Column(name="claim_no")
private String claimNo;
@Column(name="date")
private Timestamp created;
private String category = "";
private String subcategory;

/* Transient properties */
@Transient
private boolean updated = false;

public String getUser() {
    return userid; }

public void setUser(String u) {
    userid = u;}

public String getNote() {
    return note; }

public void setNote(String n) {
    note = n; }

public String getClaimNo() {
    return claimNo; }

public void setClaimNo(String c) {
    claimNo = c; }

public Timestamp getTimestamp() {
    return created;
}
public void setTimestamp(Timestamp timestamp) {
    this.created = timestamp;
}

public String getCategory() {
    return category;
}

public void setCategory(String category) {
    this.category = category;
}

public String getSubcategory() {
    return subcategory;
}

public void setSubcategory(String subcategory) {
    this.subcategory = subcategory;
}

public boolean isUpdated() {
    return updated;
}

public void setUpdated(boolean updated) {
    this.updated = updated;
}

@PrePersist
@PreUpdate
private void fillDate() {
    setTimestamp(new Timestamp(System.currentTimeMillis()));
}
然后我用调试器查看这个ArrayList,它是空的,我在其他阶段也看到它是大小为0的ArrayList

任何人都知道为什么会这样。我被难住了


格兰特

我想出来了。简单愚蠢的错误。我一直在使用我的开发数据库处理通过一个简单的数据库连接收集的所有数据,尽管我未能将persistence.xml更改为dev数据库。一旦我这样做了,显示数据就没有问题了

不起作用的查询包括三个命名查询。在SQL客户机(pgAdminIII或psql)中运行它们时会发生什么?如果它们有效,问题就出在你的应用程序代码中;如果它们不起作用,问题可能出在database.Catcall中,我做的第一件事就是记录Note.getByClaimNo命名查询并在psql客户机中运行,因为它是应用程序中最明显的。查询在psql控制台中运行良好。您是通过手动连接所有行来测试它,还是复制并粘贴连接后生成的SQL语句?我认为getResultList()不能返回NULL。可能值得检查。我将字符串放入一个java类,并将其打印到控制台。我将查看空返回,我只是检查了文档,但没有看到,我将返回并进行更多的调试,看看我是否只是看得太早。
currentNotesArray = em.createNamedQuery("Note.getByClaimNo").
            setParameter("claim_no", claimNumber).getResultList();