• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubts in EJB

 
Smita Kulkarni
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answers to your questions are
(1) YES
(2) YES
You were asked to say YES or NO
Bye
 
Smita Kulkarni
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer to your first question is Yes.
This is made possible with using BMP(Bean-Managed Persistent) Entity Beans.
 
SRINI VASAN
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Shakti Sharma
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 449
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic