I'm just getting started with JPA, creating stateless session beans from the JPA entities, then accessing the beans through a web service. While I have a lot of experience developing database backed web services "the old way", I have some questions about what's going on behind the scenes with this new "annotation driven approach".
What I see is, NetBeans sort of directs you to build applications in this manner though their wizards.
- Create an Enterprise Application with EJB and Web Application modules.
- Create Entity classes. I created mine from an existing database.
- Create session beans from the entity class.
- Create Web services from the session bean.
It all looks pretty simple, but what's going on behind the scenes? Specifically:
- I see that the web service (created with the
@WebService
annotation) references my stateless session bean (using the@EJB
reference).What happens here? Does it just grab an instance of the EJB from the application server's EJB pool?
Nevermind. I was thinking of an instance where there was more than 1 table - meaning more than 1 type of Entity class and more than 1 type of EJB. I was looking at the web service and just seeing the@EJB
reference and didn't understand who it was getting the bean type from that annotation. Just below that however, it the reference to the local bean interface - so that's that.- If there is more than 1 type of EJB deployed to the server, how does it know which one to grab?
- The EJB is defined via the
@Stateless
and@Local
annotations. The bean implementation references anEnityManager
via the@PersistenceContext
annotation.- Where is the jndi lookup to the database done (maybe in the
persistence.xml
file)? - Do all of the EJBs share a common
EntityManager
(assuming theEntityManager
is thread safe)? If not, I know that theEnityManager
utilizes a second level cache to help reduce trips to the database, are these caches somehow kept in sync?
- Where is the jndi lookup to the database done (maybe in the
I know this is a lot of questions, but they're all sort of related and there seem to be a lot of complicated concepts for something that's so easy to build through the wizards. I want to make sure I understand what's all going on here.
Thanks in advance!