cancel
Showing results for 
Search instead for 
Did you mean: 

Retriving data from database through EntityBean to WebDynpro

Former Member
0 Kudos

Dear SDN's,

I have integrated my EJB appliaction into WebDynpro via Data Access Command Bean.

Here is my scenario.

1.Created a Dictionary Project,

2.Created a EntityBean,

In Entity Bean, i have created a finder method using the query - FindByAllAccounts

used the EJB QL to retrieve the records from the database using the following syntax in EntityBean.

<b><query>

<query-method>

<method-name>findByAllAccounts</method-name>

<method-params/>

</query-method>

<ejb-ql>select object(s) from ServiceTypeBean s</ejb-ql>

</query></b>

3.In Session bean, the viewAllServiceTypes method which will be invoked from within the Command Bean is called the entity bean of the local home, findByAllAccount

Command Bean invoked the session bean, viewAllServiceTypes. It returns the resultSet dataType

In Web Dynpro, add the code shown below in the QueryAll button and also, the EAR file is added to the Web Dynpro as a sharing reference

After the execution of my WebDynpro,

it returns no records. It should return 2 records. I dont know where it goes wrong.

Correct me if anything is worng here.

Here what my doubt is, the return of the Entity bean and Session Bean is Collection type.

If i store the retrieved records in collection Object like vector, how can i differentiate each record to display as individual.

anyway I tried by converting the Collection Object to ResultSet.

Here is the code in the command Bean,

public ResultSet execute1()

{

Collection col=new Vector();

ResultSet rs=null;

try{

col=theSrType.viewAllServiceTypes();

rs=(ResultSet) col.iterator();

}catch(Exception e){

e.printStackTrace();

}

return rs;

}

I am just calling the execute1() method in my Webdynpro program.

I know here something is wrong but my aim is to retireve set of records from database via Entity bean to display in WebDynpro Table.

Your help will be appreciated.

Regards,

Sireesha.B

Accepted Solutions (0)

Answers (2)

Answers (2)

monalisa_biswal
Contributor
0 Kudos

For helper class you have to create a separate java project.

Auxillary class is required to store the data from the entity bean in a form that can be displayed.

For this purpose, the auxillary class must contain a field for each relevant value. The fields will be named similar to their definition in the entity bean.

For example:Entity Bean has persistent fields id, firstname, lastname.

Auxillary Class should contain all these fields and getter and setter method to access these fields.

In your EJB module project give this auxillary class project reference.

In the session bean parse the collection of Entitty Bean local references and convert it to collection of auxillary class reference.

In the command bean declare a collection type variable, write getter and setter methods for this variable, call the session bean method and assign it declared collection type variable.You dont need to write any logic inside command bean method.

Go through this URL for more information.

<a href="http://help.sap.com/saphelp_erp2005vp/helpdata/en/70/13353094af154a91cbe982d7dd0118/frameset.htm">http://help.sap.com/saphelp_erp2005vp/helpdata/en/70/13353094af154a91cbe982d7dd0118/frameset.htm</a>

Message was edited by:

Monalisa Biswal

monalisa_biswal
Contributor
0 Kudos

Entity Bean returns collection of EJB local reference.

You need to iterate over this collection, type cast it to Entity bean Local reference type and add to a new collection which will hold references of helper class.

Collection <Collection Name> = <Entity Bean>LocalHome.findAllPipingLines();

Collection <Collection for holding auxilarry class reference>

= new ArrayList();

Iterator iter = <Collection Name>.iterator();

while (iter.hasNext()) {

<Entity Bean>Local <Entity BeanLocal ref> = (<Entity Bean>Local) iter.next();

<Auxillary Class> <Auxillary Class ref>= new <Auxillary Class>();

<Auxillary Class ref>.set<fld1>(<Entity BeanLocal ref>.get<fld1>());

<Auxillary Class ref>.set<fld2>(<Entity BeanLocal ref>.get<fld2>());

<Collection for holding auxilarry class reference>.add(<Auxillary Class ref>= );

}

return <Collection for holding auxilarry class reference>;

Former Member
0 Kudos

Hi Biswal,

Thanks for ur support,

Can you explain more clearly like wiht na example of 2 fields!

Where should we define Auxilry class? etc.,

Thanks,

sireesha.B