Forums Register Login

where JPA code should go?

+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
 

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.
Won't you please? Please won't you be my neighbor? - Fred Rogers. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1506 times.
Similar Threads
Persitence confusion. Please help.
JPA Transaction management
MZs Notes - Pg 159
JPA not working with EJB3
Entity not persisting
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 05:08:22.