Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

where JPA code should go?

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please have a look at following code:



It's from https://glassfish.dev.java.net/javaee5/persistence/persistence-example.html. It's kind of testing code for JPA.

Where should I write this code in my project???

Should I write this in stateless session bean (as if I was performing database operations in stateless session bean before using JPA) or in POJO???

Or somewhere else???

Thanks.
[ December 04, 2007: Message edited by: ankur rathi ]
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you can write it inside your stateless session bean. But, it depends on what other responsibilities you have given your session bean.
Does it do just the job of setting up the entity manager and calling the business methods and finshing off the work? or it has more responsibilities. Also depends on how many entity managers you use.

I suggest having a separate layer which does this and return after the job is done. Moreover, even if you want to replace the entire entity manager stuff and mange your objects(POJOS) all by yourself you can just replace it separately without any change in the session code (Mind you this is the client interface to the app running inside your server).

Also what made you ask the question that this should be written inside your POJO?
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Arun Kumarr:
Well you can write it inside your stateless session bean. But, it depends on what other responsibilities you have given your session bean.
Does it do just the job of setting up the entity manager and calling the business methods and finshing off the work? or it has more responsibilities. Also depends on how many entity managers you use.


It does just that - creating EntityManagerFactory, EntityManager object and calling business methods. Not sure about the number of entity managers I will be required.


I suggest having a separate layer which does this and return after the job is done. Moreover, even if you want to replace the entire entity manager stuff and mange your objects(POJOS) all by yourself you can just replace it separately without any change in the session code (Mind you this is the client interface to the app running inside your server).


Okay. So what kind of layer it cab be??? Can't that code go in POJO and I call it from stateless session bean.


Also what made you ask the question that this should be written inside your POJO?


Actually I should have been more specific. I meant, the code should go in any of the implementation of DAO. And creating 'DAO Factory object' and 'DAO object' code can go in stateless session bean. Does this make sense?

Thanks a ton.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic