aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Doubts in EJB 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 "Doubts in EJB" Watch "Doubts in EJB" New topic
Author

Doubts in EJB

Smita Kulkarni
Greenhorn

Joined: Dec 01, 2000
Posts: 5
Hi,
I have the following two questions regarding Enterprise Beans.

1. Can an Entity Bean map to two tables in the database. If yes, how can it be done.
2. Can we have a 'synchronized' method in an Enterprise bean. Reasons for both the answers ('yes' and 'no').
Waiting for answers,
Thanks.
Venkat Ammisetty
Ranch Hand

Joined: Nov 25, 2000
Posts: 42
Answers to your questions are
(1) YES
(2) YES
You were asked to say YES or NO
Bye


Venkat Ammisetty
Smita Kulkarni
Greenhorn

Joined: Dec 01, 2000
Posts: 5
That was funny but I had asked for the reasons for the answer. Jokes apart, I would be grateful if you give me the explanation for your answer.
Thanks.
Carl Desborough
Greenhorn

Joined: May 08, 2000
Posts: 22
It is possible to have a synchronized method in an ejb, but it might not be a good idea ... one of the ideas behind ejbs is that low level things (like threading) should be handled by the container and if you start coding them yourself, it may interfere with what the container is doing.
There was an article in javaworld on what you can but shouldnt do in ejbs, and that was one of the things they mentioned.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Can answer just one...
Sure, you can have synchronized methods in your EJB. Not that it makes any difference. The container will not allow more than a single thread to access your EJB object anyway, and you may not spawn your own threads that might do this.
Asuthosh Borikar
Ranch Hand

Joined: Sep 29, 2000
Posts: 75
The answer to your first question is Yes.
This is made possible with using BMP(Bean-Managed Persistent) Entity Beans.
SRINI VASAN
Ranch Hand

Joined: Aug 29, 2000
Posts: 48
For accessing more that two tables you could use view in database which combine two tables ..
Else u could use tool like TOPLINK which writes teh complex queries ..

Regards,
srini
YOu could contact me in srinivas_an_2000 if it is too immediate..

You can contact me in srinivas_an@yahoo.com
Shakti Sharma
Ranch Hand

Joined: Dec 19, 2000
Posts: 60
with bmp you can have any number of tables in one entity bean.
you can use stored procedure or table directly to manage persistence
Badal Kotecha
Ranch Hand

Joined: Sep 06, 2000
Posts: 42
Originally posted by Smita Kulkarni:
[B]Hi,
I have the following two questions regarding Enterprise Beans.

1. Can an Entity Bean map to two tables in the database. If yes, how can it be done.
>> With CMP u can't do it directly except that of using views. The Other way is to use BMP and write ur own implementations for ejbCreate and ejbPostCreate...
Reply me if there is any other way....
2. Can we have a 'synchronized' method in an Enterprise bean. Reasons for both the answers ('yes' and 'no').
>> We can have it but it will directly affect the performance becaz threading is handled completely by Containers of Application server and dont know the way of their handling. And Containers uses single threading model, but still there is a way called reentering the bean.
For more help u can refer orielly's EJB book *3rd or 4th chapter i dont remember exactly...
Chalo bye
Regards.
Badal
Sid Vicious
Greenhorn

Joined: Jan 05, 2001
Posts: 8
With respect to the synchronization, I would avoid using
it - the EJB 2.0 spec actually forbids it. Check section
23.1.2. Your apps probably will not be forward compatible.
Vijay S. Rathore
Ranch Hand

Joined: Oct 29, 2001
Posts: 449
Hi Sid Vicious,
It's 24.1.2 (Programming restrictions).

Moreover it says
An enterprise Bean must not use thread synchronization primitives to synchronize execution of
multiple instances.
must not is not same as can not.


SCJP, SCJD, SCWCD1.4, IBM486, IBM484, IBM 483, IBM 287, IBM141, IBM Certified Enterprise Developer - WebSphere Studio, V5.0
Author of IBM 287 Simulator Exam
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubts in EJB