• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Entity Bean Problem

 
Prakash Dwivedi
Ranch Hand
Posts: 452
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,
I am new to ejb, i have read that entity beans are view to the database and in ejb we dont deal with database directly rather we deal with entity beans.
My problem is if i want to find out all the employees who have salary greater than 5000(or any such query) how am i going to do this in entity beans.
plz help
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prakash,
I think the answer to your question is the most popular answer in computer software, "it depends". It depends on several factors. Firstly, it depends on whether you wish to use BMP or CMP entity beans. Secondly, it depends on what EJB container you are using, and what version of the EJB specification it supports. If you are using CMP beans and an EJB container that supports (at least) version 2.0 (of the EJB specification), then you could use EJB-QL.
If you haven't done so yet, I suggest you read the EJB specification (the version that your EJB container supports) -- I found that very helpful in understanding EJB. I also recommend the following book:
http://www.oreilly.com/catalog/entjbeans3/
Hope this has helped you.
Good Luck,
Avi.
 
Prakash Dwivedi
Ranch Hand
Posts: 452
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can i use EJB-QL with ejb1.1 also?
 
james edwin
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prakash,
with EJB1.1 ,You can't use EJB-QL,as this is introduced in EJB2.0 only.
Cheers,
James Edwin
 
Prakash Dwivedi
Ranch Hand
Posts: 452
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using ejb1.1 websphere, is there any alternative to EJB-QL, otherwise i am coming back to my original question, i.e.
if i want to find out all the employees who have salary greater than 5000(or any such query) how am i going to do this in entity beans(CMP ejb1.1).
plz help
[ December 30, 2002: Message edited by: Prakash Dwivedi ]
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prakash,
I may be wrong, but it seems to me you have a misconception about EJB. Each instance of an entity bean represents an "entity". Using your example, each entity bean instance would represent one employee. Again, I am assuming (using your example) that an "employee" is actually a single row from your "employee" (database) table. So when you are working with an entity bean instance, you are actually working only with the data for a single employee.
A "finder" method usually represents a single database query. I suppose the method signature for the finder method (from your example) would be:
Collection findBySalary(Float salary) throws FinderException;
This method would only execute the query:
SELECT employee_pk_column(s)
FROM employee_table
WHERE emp_salary > salary (= method parameter)
I don't know websphere, but it must give you some way of mapping the SQL query to the "finder" method (in the case of CMP entity beans). If you are using BMP entity beans, you would write JDBC code in the "ejbFindBySalary" method to execute the above query.
But remember, if you want to use another query to select data from the "employee" table (maybe by "job-title"?), then you would need to create another "finder" method.
Let me repeat my recommendations from my previous reply -- regarding relevant literature. EJB is not simple, but there is a wealth of available information to help you. Please access it (if you haven't already done so). I don't think there is any other way to become proficient in EJB (assuming that is your goal).
Good Luck,
Avi.
 
Brijesh Tripathi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prakash,
You can solve your query either by using CMP or by
BMP whatever you want . with CMP you need to write
ejb-QL in ejb-jar.xml within <ejb-ql> tag.
whereas with BMP yon can write your query code in
your Bean file something like ejbFindByAccount() method and its corresponding definition in Home i/f of your Bean jar file.
Hope this will solve your query.
Brijesh.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic