views:

499

answers:

3

Hello!

I am currently in the process of learing about Java EE, EJB3 and . So far I am running a JBoss application server and a Oracle database. I have written a stateful session bean which retrieves data from the database through JPA entities.

My goal is to have a simple client speaking to a server by calling methods in a stateful bean. But I have too little experience to know how granular these beans should be, how the should interact with my entity beans and so on.

I am far from perfect, but books and simple tutorials don't really help anymore. I looked for open source projects that are actually using these kind of technology in order to get the idea how to design my application. A websearch did not bring up much, except a PetStore example from 2006. I would be glad if anyone could point me to some useful resource, not necessartily a real project, but maybe more advanced examples.

+1  A: 

I've found "EJB 3 In Action" book as very useful to understand how to develop your beans.

Mykola Golubyev
Thanks, I going to check it out on monday.
sebastiangeiger
+2  A: 

Sounds like you're looking to learn "what kind of logic to I code in the EJB tier" instead of "how do I code the EJB tier".

The textbook answer would be to say "most business logic should be implemented at the EJB tier".

Practically speaking, I would base my decisions on something according to this workflow:

  1. Suppose my business case is to implement a Bank Account Inquiry service. So, I roughly know that an AccountInquiryService is required.
  2. Typically, the main channel where this service would be invoked is from a web tier, i.e. a web application where the user can perform inquiries on his accounts.
  3. However, in the interest of code reuse, I figure that there may be a use case, where I may need to code a Java desktop client that will also perform account inquiries.
  4. So, I try to construct the AccountInquiryService such that the same methods are applicable from both the web and desktop client tiers. I must not need to add different methods just to be able make both channels work.

Sorry if I got the gist of your question wrong. Hope this helps.

feicipet
You're right, maybe my question is a bit misleading. I read about the textbook answer and your example hits the spot, but it answers the question I alreay solved before I posted this question. My problem is a bit further on the implementation level. It's more on how are JPA Entities used by Session Beans. How many Session Beans do I need an such things.
sebastiangeiger
Your question is still rather vague, but I'll try my best.JPA Entities are just reflections of business objects mapped to the DB. Strictly speaking, they're not even "EJB beans". Your EntityManager will get whatever data is needed and map them into your JPA beans so that you can use them as you would any POJO. So, there's no practical limit on how many entities you can use, it depends more on your DB design.SessionBeans typically group a similar set of functions into one. So that's entirely up to you to design. For e.g, AccountInquiryService and FundTransferService.
feicipet