User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 426,140 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,698 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 2132 | Replies: 4
Reply
Join Date: Sep 2006
Location: India
Posts: 79
Reputation: parthiban is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 6
parthiban's Avatar
parthiban parthiban is offline Offline
Junior Poster in Training

Question How to call a EJB method from Session bean method

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 199
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

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

  #2  
Mar 27th, 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  
Join Date: Sep 2006
Location: India
Posts: 79
Reputation: parthiban is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 6
parthiban's Avatar
parthiban parthiban is offline Offline
Junior Poster in Training

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

  #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 .


public String ejbCreate(String empid, String firstname, String lastname, String circle, String subcircle, String created_date, String updated_date) throws CreateException {
        try{
            insertRow(empid,firstname,lastname,circle,subcircle,created_date,updated_date);
        }catch(SQLException ex){
            throw new EJBException("ejbCreate: " + ex.getMessage());
        }
        this.empid = empid;
        this.firstName = firstname;
        this.lastName = lastname;
        this.Circle = circle;
        this.Subcircle=subcircle;
        this.Created_Date=created_date;
        this.Updated_Date=updated_date;
        return empid;
        
    }

private void insertRow(String empid, String firstName,
            String lastName, String Circle,String Subcirle,String Created_Date,String Updated_Date) throws SQLException{
        makeConnection();
        String insertStatement = "insert into Employee values ( ? , ? , ? , ?,?, ?,? )";
        PreparedStatement prepStmt = con.prepareStatement(insertStatement);
        
        prepStmt.setString(1, empid);
        prepStmt.setString(2, firstName);
        prepStmt.setString(3, lastName);
        prepStmt.setString(4, Circle);
        prepStmt.setString(5, Subcircle);
        prepStmt.setString(6,Created_Date);
        prepStmt.setString(7,Updated_Date);
        
        
        prepStmt.executeUpdate();
        prepStmt.close();
        releaseConnection();
    }


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  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 199
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

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

  #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  
Join Date: Sep 2006
Location: India
Posts: 79
Reputation: parthiban is an unknown quantity at this point 
Rep Power: 3
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

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

Thanks
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 4:54 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC