How to persist data with BMP Bean in WebSphere Application Server - Websphere

This is a discussion on How to persist data with BMP Bean in WebSphere Application Server - Websphere ; We are creating the bean using some primary key. After that we set some values to that Bean. While retrieving the data from that Bean, we are not able to get the values what we have set to the bean. ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: How to persist data with BMP Bean in WebSphere Application Server

  1. How to persist data with BMP Bean in WebSphere Application Server

    We are creating the bean using some primary key.
    After that we set some values to that Bean.
    While retrieving the data from that Bean, we are not able to get the values what we have set to the bean.

    TestBean.java
    =============

    Collection getValues()
    {
    List list = null;
    Resultset rs = "select * from test";
    Test test = null;

    while(rs.next())
    {
    test= (Test)home.findByPrimaryKey(new Key());
    test.setId(rs.getInt(1));
    test.setName(rs.getString(2));
    if(list =! null){
    list = new ArrayList();
    }
    list.add(test);
    }
    return list;
    }

    Example.java
    --------------
    somemethod(){
    Test test = null;
    Collection cls = test.getValues();
    Iterator itr = cls.iterator();
    while(itr.hasnext())
    {
    test = (Test) itr.next();
    STring id = test.getId();
    System.out.println("id "+ id);
    }

    }


    In the Example.java, we are getting default values like 0, 0.00 and nulls instead the values we set.

    We thought its a problem with persisting the state of the Bean.

    If you have any idea about this BMP persistency, let us know ASAP.

    Thanks in advance







  2. Re: How to persist data with BMP Bean in WebSphere Application Server

    For BMP (bean-managed persistence), you would need to place code in the bean's ejbStore() method to write the bean's instance variables to some form of persistent storage, and place code in ejbLoad() to read data into the bean's instance variables. The EJB specification from Sun outlines specifically how this works, or one of the EJB development books by various authors. Also, it is probably not correct to be calling findByPrimaryKey() from inside the bean code itself; typically the *client* of the bean is who calls this method.

    sarada_kml@yahoo.co.in wrote:
    > We are creating the bean using some primary key.
    > After that we set some values to that Bean.
    > While retrieving the data from that Bean, we are not able to get the values what we have set to the bean.
    >
    > TestBean.java
    > =============
    >
    > Collection getValues()
    > {
    > List list = null;
    > Resultset rs = "select * from test";
    > Test test = null;
    >
    > while(rs.next())
    > {
    > test= (Test)home.findByPrimaryKey(new Key());
    > test.setId(rs.getInt(1));
    > test.setName(rs.getString(2));
    > if(list =! null){
    > list = new ArrayList();
    > }
    > list.add(test);
    > }
    > return list;
    > }
    >
    > Example.java
    > --------------
    > somemethod(){
    > Test test = null;
    > Collection cls = test.getValues();
    > Iterator itr = cls.iterator();
    > while(itr.hasnext())
    > {
    > test = (Test) itr.next();
    > STring id = test.getId();
    > System.out.println("id "+ id);
    > }
    >
    > }
    >
    >
    > In the Example.java, we are getting default values like 0, 0.00 and nulls instead the values we set.
    >
    > We thought its a problem with persisting the state of the Bean.
    >
    > If you have any idea about this BMP persistency, let us know ASAP.
    >
    > Thanks in advance
    >
    >
    >
    >
    >
    >


+ Reply to Thread