How to call a EJB method from Session bean method

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2006
Posts: 80
Reputation: parthiban is an unknown quantity at this point 
Solved Threads: 6
parthiban's Avatar
parthiban parthiban is offline Offline
Junior Poster in Training

How to call a EJB method from Session bean method

 
0
  #1
Mar 27th, 2007
Hi all,

I'm new to J2EE programming. I have a simple doubt .

I have already created a lookup method for EJB bean in Session bean .

My question is how to call a method of an ENTITY bean (say insertRow) from SESSION bean method(Say invoke_insertRow) .

Please provide me an example code .

Thanks in advance.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: How to call a EJB method from Session bean method

 
0
  #2
Mar 28th, 2007
You don't.
You create a new entity, and it takes care of its database access itself.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 80
Reputation: parthiban is an unknown quantity at this point 
Solved Threads: 6
parthiban's Avatar
parthiban parthiban is offline Offline
Junior Poster in Training

Re: How to call a EJB method from Session bean method

 
0
  #3
Mar 28th, 2007
Originally Posted by jwenting View Post
You don't.
You create a new entity, and it takes care of its database access itself.
Hi Jwenting ,
First of all thanks for your reply . I think i didn't correctly specified what i need .

Task i need to accomplish :
=================
I have to read ACCESS tables and EXCEL sheets to convert in to XML file so that i can store that values in SQL SERVER using JOnAS Application Server .

Here's my story which will tell what i need :
===========================

I created SESSION BEAN program which contains function which will convert ACCESS/EXCEL file in to XML .

I also created ENTITY BEAN program which contains function to store the data in SQL SERVER(the data which are obtained from that XML file).

i have developed that ENTITY module in such a way that i need to pass the data as arguments of create method of that ENTITY BEAN as follows .


  1. public String ejbCreate(String empid, String firstname, String lastname, String circle, String subcircle, String created_date, String updated_date) throws CreateException {
  2. try{
  3. insertRow(empid,firstname,lastname,circle,subcircle,created_date,updated_date);
  4. }catch(SQLException ex){
  5. throw new EJBException("ejbCreate: " + ex.getMessage());
  6. }
  7. this.empid = empid;
  8. this.firstName = firstname;
  9. this.lastName = lastname;
  10. this.Circle = circle;
  11. this.Subcircle=subcircle;
  12. this.Created_Date=created_date;
  13. this.Updated_Date=updated_date;
  14. return empid;
  15.  
  16. }
  17.  
  18. private void insertRow(String empid, String firstName,
  19. String lastName, String Circle,String Subcirle,String Created_Date,String Updated_Date) throws SQLException{
  20. makeConnection();
  21. String insertStatement = "insert into Employee values ( ? , ? , ? , ?,?, ?,? )";
  22. PreparedStatement prepStmt = con.prepareStatement(insertStatement);
  23.  
  24. prepStmt.setString(1, empid);
  25. prepStmt.setString(2, firstName);
  26. prepStmt.setString(3, lastName);
  27. prepStmt.setString(4, Circle);
  28. prepStmt.setString(5, Subcircle);
  29. prepStmt.setString(6,Created_Date);
  30. prepStmt.setString(7,Updated_Date);
  31.  
  32.  
  33. prepStmt.executeUpdate();
  34. prepStmt.close();
  35. releaseConnection();
  36. }
What i planned to fetch XML data:
=====================

I will develop a function to parse XML file in that SESSION BEAN ( which created that XML file) to obtain that data and i have to pass that values to the above function which is in ENTITY BEAN.

I came to know that i can't invoke create method of ENTITY bean so i need to invoke that insertRow function directly (which actually stores data in SQL SERVER) .

So please guide me HOW CAN I INVOKE a ENTITY BEAN method (insertRow) from an SESSION BEAN with sample coding .

I think it's quite a big story .Thanks for your patience

Thanks in advance.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: How to call a EJB method from Session bean method

 
0
  #4
Mar 28th, 2007
You do NEVER call those methods directly, how often do I have to repeat that?

In fact, if you don't understand that you can't even call a private method from another class (or even another instance of the same class) you should not be doing any J2EE stuff AT ALL but start with an introductory tutorial on Java.

You should also do some introductory tutorial on EJBs after that, and one that handles MODERN EJBs, as directly doing JDBC access from entity beans is NOT the way to do things, and hasn't been for years.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 80
Reputation: parthiban is an unknown quantity at this point 
Solved Threads: 6
parthiban's Avatar
parthiban parthiban is offline Offline
Junior Poster in Training

Re: How to call a EJB method from Session bean method

 
0
  #5
Mar 30th, 2007
Hi Jwenting ,
Sorry for such a silly question .

Thanks
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC