0

サーバー側でJDOを使用して永続化された家のリストにアクセスするGWTアプリを構築しています。家のリストは、RPC「getHouseService」を介してクライアント側に移動され、表示および操作されます。後でサーバー側に返されて保存されることはありません。

アプリを実行して RPC サービスを実行すると、クライアントは常に空のリストを取得します。テスト中に、デバッグ モードの私の IDE (Eclipse) は、getHouse で返されるリストの値が StreamingQueryResult であることに注意します。

私は何を間違っていますか?? この問題に 1 週​​間以上悩まされていますが、関連する解決策がオンラインで見つかりません。

これは、データの永続性を操作するために書いたコードです。

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

}
4

1 に答える 1

0

これは、この質問で説明されているのと同じ問題である可能性があります: GWT retrieve list from datastore via serviceimplリストを要約すると遅延ロードされるため、RPC 経由でリストを返すと、まだ読み取られず、空のリストが返されます。https://stackoverflow.com/a/7646549/66416の質問に対する回答は、リストを返す前にリストを呼び出すことを提案していますsize()。これにより、リストが読み込まれます (ただし、これが最もエレガントなソリューションであるかどうかはわかりません)。

于 2012-07-23T12:19:19.577 に答える