2011-03-18 59 views
0

我有一個應用程序,使用hibernat創建的實體收集它的一些數據,其餘的收集與簡單的jdbc數據庫連接和sql語句。保存也是一樣的。我最近從Postgresql 8.4將數據庫升級到了Postgresql 9.0,並注意到與實體收集的所有數據都不再顯示。我可以用entites保存數據,但不能顯示相同的數據。Hibernate和Postgresql 9.0與Java

我升級到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; 
} 

}

所以我創建的說明類別,有下列對象:

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())); 
} 

}

並在此實體不工作我使用以下方法來創建它。

currentNotesArray = em.createNamedQuery("Note.getByClaimNo"). 
      setParameter("claim_no", claimNumber).getResultList(); 

然後我看這個ArrayList中使用調試器,它是空的,我已經在其他階段看到它的大小爲0的ArrayList爲好。

任何人都有任何想法,爲什麼會這樣。我很難過。

格蘭特

+0

不起作用的包括三個命名查詢。在SQL客戶端(pgAdminIII或psql)中運行它們時會發生什麼?如果他們工作,這個問題在你的應用程序代碼中;如果他們不工作,問題可能在數據庫中。 – 2011-03-21 11:21:10

+0

Catcall,我做的第一件事之一是使用Note.getByClaimNo命名查詢並在psql客戶端中運行,因爲它是應用程序中最明顯的。該查詢在psql控制檯中工作得很好。 – grantk 2011-03-21 12:18:55

+0

您是通過手動連接所有行來測試它的,還是複製並粘貼了連接導致的SQL語句? – 2011-03-21 12:36:30

回答

0

我想出了這一個。簡單的愚蠢的錯誤。我一直在使用我的開發數據庫來處理通過簡單數據庫連接收集的所有數據,儘管我無法將persistence.xml更改爲dev數據庫。一旦我這樣做,顯示數據就沒有問題。