Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to call an entity bean?  RSS feed

 
Rituparna Duttagupta
Ranch Hand
Posts: 55
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends!
i am using or rather trying to use entitybeans for the 1st time in my application. i am familiar with session beans and have worked on them earlier.
i want help on how to call an entitybean? from where it should be called?
we call session beans from jsp files, can an entitybean be called like that only?
please give an elaborate reply.
thanks all in advance.....
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
First of all you let us know what version of EJB you are using. I am assuming it must be 2.x as you mentioned Entity Beans.
Yes,they can be called from JSP which is a bad idea. But the way you call them remains same as you call session beans. That is first you do lookup, get hold of home and then call create/finder/selector ( till EJB 2.x) and then work with the entity bean.
From EJB 3.0, this is completely revamped because now there are no more things as Entity Beans. There are JPA entities which are simple POJOs with annotations.
These can be used by injecting PersistenceContext into the Session bean and then using it to interact with Entities.

Hope this helps.

Regds,
Amit
 
Rituparna Duttagupta
Ranch Hand
Posts: 55
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WELL, actually i m new to entity beans. i am using NETBEANS 6.9.1, i dont know which version they use. i ve developed an entity class.
i think developing is the best way to learn, so...
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I believe it to be the EJB then. Does it have annotations like @Entity and others?
Also any IDE will allow you to choose from the available versions of implementation for Enterprise Java Beans.

regds,
Amit
 
Ravi C Kota
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Amit mentioned, calling Entity beans is similar to the way you do for sessionbean. I have not worked on EJB3.x, but the most straight forward and the only way I know is to lookup through JNDI registry.

Also, I know that a JPA is introduced from EJB 3.x, but EntityBeans are not deprecated, except that they are not recommended. But as far as I know, you can still use Entitybeans of 2.x in your 3.x implementation. I may be wrong here, but would appreciate, if any one could clarify on that.
 
Rituparna Duttagupta
Ranch Hand
Posts: 55
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well. thanks for this information.
but why is that entitybeans not recommended in EJB 3.x?
is that means that using JDBC is better than using entity beans in an application?
and is there any difference in EJB 3.x and EJB 2.x regarding sessionbeans?
 
Ravi C Kota
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but why is that entitybeans not recommended in EJB 3.x?


Because they devised a better approach in EJB3.X .. The fact here is, EntityBeans 2.x is over complex with lots of interfaces (local, remote, home etc) and does not map well to relational databases (most common kind of database system in usage). There are several differences which you can learn by googling benefits of ORM. Hibernate came up with a solid ORM concepts, which was developed with the idea of reducing Object and Relational world differences. I somewhere heard that persistance API of EJB3.0 is influenced by Hibernate ORM concepts and built a better ORM system based on several such concepts. The best resource to read for understanding the differences and motives to bring up a new concept is "Mastering EJB 3.0" . This book has a section on Pre and Post EJB 2.x era.


is that means that using JDBC is better than using entity beans in an application?


Not necessarily, JDBC and EntityBeans/JPA though deal with persistence has different approaches and trade offs. Personally I do not keep myself away from JDBC, and follow ORM all the time. Some of the usecases, I think can be handled with plain JDBC efficiently compared to more complex ORM implementation. After all JDBC is not obsolete.

and is there any difference in EJB 3.x and EJB 2.x regarding sessionbeans?


The basic concept of enterprise beans and the purpose did not change with these versions, but the way they are being developed is changed. Obviously there is lot less interfaces involved in 3.0. You can expose your POJO as session beans, that is there is no restriction of implementing any interfaces unlike 2.x. There are several such benefits.... easy learning, easy development etc

As I suggested, reading through "Mastering EJB 3.0" would give you a very clear understanding of pre/post worlds.
 
Rituparna Duttagupta
Ranch Hand
Posts: 55
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THANKS A LOT for this elaborate description. its truelly beneficial for a novice like me.
i'll certainly go thorughly through every page of 'Mastering EJB 3'.
THANKS A LOT ONCE AGAIN.
:-)
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!