Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question
0

Problem with read POJO out of Space

Hi, I create a POJO class with a field of type of Hashtable. I have no problem to write it into space.But if the hashtable is filled with data , I failed to read the POJO out using template or query. And the Only way I found is to usetemplate identical to Data. Anyone has idea what's going wrong ,why I can't match the POJO, how can i retrieve the POJO from Space, Thanks

Sample Code

Main Program

import org.openspaces.core.GigaSpace; import org.springframework.beans.factory.InitializingBean;

import com.hp.engine.common.Data;

public class TestMain implements InitializingBean{

private GigaSpace gigaSpace;

public void setGigaSpace(GigaSpace gigaSpace) {
    this.gigaSpace = gigaSpace;
}

public void afterPropertiesSet() throws Exception {

                      Data a = new Data("1");
          gigaSpace.write(a);

                      Data result = gigaSpace.take(new Data());
          System.out.println(result.getId());   // *Succeed when hashtable is empty*

                     Data b = new Data("2");
                     b.put("key","value"); // *Put some data in the hashtable in POJO*
                     gigaSpace.write(b);
                     result = gigaSpace.take(new Data()); // *Null reference, Failed*     
                     result = gigaSpace.take(new Data("2")); // *Null reference ,Failded again*

                     result = gigaSpace.take(b); // *succeed on if template is identical to original data*
            }

}

Class POJO import java.util.Hashtable; import com.gigaspaces.annotation.pojo.SpaceClass; import com.gigaspaces.annotation.pojo.SpaceId;

@SpaceClass(replicate = false) public class Data {

private String id;

public Hashtable<String, String> data = new Hashtable<String,String>();


public Data(){

}

public Data(String id){
    this.id = id;
}

@SpaceId
public String getId() {
    return id;
}

public void setId(String id) {
    this.id = id;
}

public Hashtable<String, String> getData() {
    return data;
}

public void setData(Hashtable<String, String> data) {
    this.data = data;
}

public void put(String key ,String value){
    data.put(key, value);
}

public String value(String key){
    return data.get(key);
}
public boolean equals(Object o){
    if(!(o instanceof Data)){
        return false;
    }else{
        Data another = (Data) o ;
        return(another.getId() != null
        && another.getId().equals(getId())||another.getId() == getId());
    }
}
public String toString()
{
    return " Data-" + id;
}

}

{quote}This thread was imported from the previous forum. For your reference, the original is [available here|http://forum.openspaces.org/thread.jspa?threadID=1967]{quote}

asked 2008-03-05 10:02:20 -0600

peng0 gravatar image

updated 2013-08-08 09:52:00 -0600

jaissefsfex gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

You need to have the data member null in your template.

-Guy

answered 2008-03-05 10:31:28 -0600

guy sayar gravatar image
edit flag offensive delete link more

Comments

thanks, simple and works

peng0 gravatar imagepeng0 ( 2008-03-07 10:07:19 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2008-03-05 10:02:20 -0600

Seen: 34 times

Last updated: Mar 05 '08