我正在構建一個GWT應用程序,以訪問在服務器端使用JDO持久保存的房屋列表。然後通過RPC「getHouseService」將房屋列表移動到客戶端以顯示和操作。之後他們不會返回並保存在服務器端。JDO查詢返回零結果
當我運行應用程序並執行RPC服務時,客戶端總是得到一個空的列表。 在測試期間,我注意到我在調試模式下的ide(eclipse)注意到getHouse中返回列表的值是一個StreamingQueryResult。
我在做什麼錯?我一直在這個問題上停留了一個多星期,並且在網上找不到相關的解決方案。
這是我寫我的數據持久化工作代碼:
public static PersistenceManagerFactory getPersistenceManagerFactory() {
return pmfInstance;
}
public void addHouse(List<House> listofHouses) {
PersistenceManager pm = getPersistenceManagerFactory().getPersistenceManager();
try {
pm.makePersistentAll(listofHouses);
System.out.println("after makePersistentAll");
}
finally {
pm.close();
}
}
@SuppressWarnings("unchecked")
public List<House> getHouses() {
PersistenceManager pm = getPersistenceManagerFactory().getPersistenceManager();
List<House> houseList = (List<House>) pm.newQuery("select from " + House.class.getName()).execute();
return houseList;
}
衆議院類是:
package vancouverHEA.shared;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import org.datanucleus.jpa.annotations.Extension;
import com.google.gwt.user.client.rpc.IsSerializable;
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class House extends Building implements IsSerializable {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private Long key;
@Persistent (serialized = "true")
java.lang.Double landPrice;
@Persistent (serialized = "true")
java.lang.Double housePrice;
@Persistent (serialized = "true")
java.lang.Boolean forSale;
@Persistent (serialized = "true")
private java.lang.String realtorContact;
@Persistent (serialized = "true")
private java.lang.Integer listPrice;
@Persistent (serialized = "true")
private java.lang.Integer yrBuilt;
@Persistent (serialized = "true")
private java.lang.Integer yrReno;
@Persistent (serialized = "true")
private java.lang.String postalCode;
@Persistent (serialized = "true")
java.lang.Double latitude;
@Persistent (serialized = "true")
java.lang.Double longitude;
String STRATA = "Strata";
String SINGLE = "Single House" ;
public House(double landPrice, double improvPrice, String address,
String postalCode, int yrBuilt, int yrReno) {
super();
this.landPrice = landPrice;
this.housePrice = improvPrice;
this.address = address;
this.postalCode = postalCode.trim().toUpperCase();
this.yrBuilt = yrBuilt;
this.yrReno = yrReno;
}
public String getPostalCode() {
return postalCode;
}
public void setPostalCode(String postalCode) {
this.postalCode = postalCode.trim().toUpperCase();
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public double getPrice() {
return this.landPrice + this.housePrice;
}
public boolean isForSale() {
return forSale;
}
public void setForSale(boolean forSale) {
this.forSale = forSale;
}
public String getRealtorContact() {
return realtorContact;
}
public void setRealtorContact(String realtorContact) {
this.realtorContact = realtorContact;
}
public int getListPrice() {
return listPrice;
}
public void setListPrice(int listPrice) {
this.listPrice = listPrice;
}
public int getYrBuilt() {
return yrBuilt;
}
public void setYrBuilt(int yrBuilt) {
this.yrBuilt = yrBuilt;
}
public int getYrReno() {
return yrReno;
}
public void setYrReno(int yrReno) {
this.yrReno = yrReno;
}
public void setLandPrice(Double landPrice) {
this.landPrice = landPrice;
}
public double getLandPrice(){
return landPrice;
}
public void setHousePrice(Double housePrice) {
this.housePrice = housePrice;
}
public double getHousePrice() {
return housePrice;
}
}
你爲什麼要連續化Double,String,Boolean,Integer類型的字段?因此它們在查詢中不可用。很明顯,日誌會告訴你所有正在發生的事情,所以最好檢查它 – DataNucleus 2012-07-23 04:47:23