*
The moose likes EJB and other Java EE Technologies and the fly likes Entity Bean Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Entity Bean Problem" Watch "Entity Bean Problem" New topic
Author

Entity Bean Problem

Prakash Dwivedi
Ranch Hand

Joined: Sep 28, 2002
Posts: 452
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


Prakash Dwivedi (SCJP2, SCWCD, SCBCD)
"Failure is not when you fall down, Its only when you don't get up again"
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1121

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

Joined: Sep 28, 2002
Posts: 452
can i use EJB-QL with ejb1.1 also?
james edwin
Ranch Hand

Joined: Nov 22, 2001
Posts: 393
Hi Prakash,
with EJB1.1 ,You can't use EJB-QL,as this is introduced in EJB2.0 only.
Cheers,
James Edwin


Regards,
James
Prakash Dwivedi
Ranch Hand

Joined: Sep 28, 2002
Posts: 452
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

Joined: Oct 11, 2000
Posts: 1121

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

Joined: Jan 03, 2003
Posts: 1
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.


Brijesh
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Entity Bean Problem
 
Similar Threads
NetBeans and MySQL
Tools for generating Entity Classes
EJB and Hibernate
Why Entity bean is not used ?
BMT with Entity beans