• Post Reply Bookmark Topic Watch Topic
  • New Topic

Bean List?

 
Michael Hildner
Ranch Hand
Posts: 297
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
New to all this, wondering how one goes about obtaining a list when using beans. For example, I have a customer bean, with primary key of customerID. What to do if I wanted a list of all the customers that, say, are delinquent on payments?
 
Nirav Parghi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you would have to create an entity bean called customer
which captures the business concept of delinqucy in it's
attributes.
then, a client program would find the bean by findByPrimaryKey
method which is passed the primary key for the bean ; for ex :
CustomerHome customerhome = (CustomerHome)context.lookup("customer");

CustomerPK pk = new CustomerPK();
for (i=0;;i++)
{
try{
pk.id = i;
Customer customer = customerhome.findByPrimaryKey(pk);
}catch(javax.ejb.FindingException e) {break;}

if(customer.getDelinquency())
//process
}



 
Sagar Sharma
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alternatively you could create another session (stateless) bean to do the dtatabase search and call call this bean from your JSP/Servlet to return the resultset. The design choice is yours. But I would recommend a different stateless session bean to do this query as this would make your business logic more portable and reusable.
If your "search requirements" change in the future then you need to just change the fields to the method of the session bean without interfering with the Entity Bean-Customer.

Think about it.

cheers

sagar
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!