dcsimg
How to communicate between Session EJB and Entity EJB
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Izak_Wessels
Posted On:   Monday, December 29, 2003 04:22 PM

Hello All, In the past few days I have been struggling to understand how exactly Session EJB's (remote interfaces) and Entity EJB's (local interfaces) communicate. I have read up on JNDI which seems to be the way to go, but I there is still a few things unclear to me. I have created a simple session bean Catalogue. Now I have created a method in Catalogue to lookup my Entity Beans so that I can use them for my business logic. The following method provides, what I think, could be used to obtain a reference to a Entity Bean. I am using CMP, so if that makes any difference in terms of lookup code I would be glad to hear about it. // Lookup my entity beans publ   More>>

Hello All,


In the past few days I have been struggling to understand how exactly Session EJB's (remote interfaces) and Entity EJB's (local interfaces) communicate. I have read up on JNDI which seems to be the way to go, but I there is still a few things unclear to me.




I have created a simple session bean Catalogue. Now I have created a method in Catalogue to lookup my Entity Beans so that I can use them for my business logic. The following method provides, what I think, could be used to obtain a reference to a Entity Bean. I am using CMP, so if that makes any difference in terms of lookup code I would be glad to hear about it.





			
// Lookup my entity beans
public void lookupEntityBeans () throws NamingException {
Context ctx = new InitialContext();
Account accountEntity = (Account)ctx.lookup("Account");
Part partEntity = (Part)ctx.lookup("Part");
}





Now from my Catalogue Session Bean, I wish to a get the discount which is associated with a particular customer, which is stored in the Account Entity Bean. Upon retrieving that value I would store it in a local variable. Then get the price of a particular part from a Part Entity Bean and store it in a local variable as well. Then perform my business logic using the values I have extracted from the 2 entity beans.





			
// Business Method
public double computeNewPartPrice (double oldPartPrice) {
// getPartPrice is an abstract method defined in
// the local interface
oldPartPrice = partEntity.getPartPrice();
tempAccountDiscount = accountEntity.getAccountDiscount();
newPartPrice = oldPartPrice - tempAccountDiscount;
}





Question 1

Basically, is the above code listings enough to get the necessary information that I need from the entity beans?
Do I need to declare any JNDI context code in my entity beans or is that done by the container?



Question 2

If I want to find say a customer discount value, which is located in the Account Entity Bean, should I use the findByCustomerID(String custID) method OR is it taken care of for me as suggested by Mastering EJB?



Question 3

If I use CMP Entity Beans, do I still need a AccountPK class OR is that taken care of by the container as well?


Thanks    <<Less

Re: How to communicate between Session EJB and Entity EJB

Posted By:   Mahesh_Patro  
Posted On:   Wednesday, December 31, 2003 12:46 AM

Hi,

i think you forgot to give the following information in ejb-jar.xml. Bcuz Session bean if want to refer to another entity bean which is local bean then you have to declare ejb-local-ref on you session bean.








ejb/bula.bula.AccountEJB

Entity

bula.bula.Account(Local Home)

bula.bula.Account(Local)

HomeLocal(Jndi name of entity bean)





if you are using weblogic then you may noth write ""
tag but in weblogic-ejb-jar.xml you have to put following lines of Code






Account





ejb/bula.bula.AccountHomeLocal

bula.bula.Account





bula.bula.Catalog






If you want detail of more then plz visit Mastering Weblogic 8.1 book.



Regards,

Mahesh Patro.
About | Sitemap | Contact