Skip to main content

Hwo to use Jpa on servlet

6 replies [Last post]
newnet
Offline
Joined: 2009-11-03
Points: 0

I am new in jpa , I try some Jpa example on java application, but when I walk on step more try to test jpa on servlet , I get the problem on create an EntityManagerFactory , It looks like I can't use the some way that I create EntityManagerFactory method like the follow

EntityManagerFactory emf=Persistence.createEntityManagerFactory("MyJPAApplicationPU");
EntityManager em=emf.createEntityManager();
try{
EntityTransaction entr=em.getTransaction();

I Google, and find some Thread-safe issuer , any not ideal how to use jpa in servlet .
any help is appreciate !

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
newnet
Offline
Joined: 2009-11-03
Points: 0

Nice example !

Sanjeeb Sahoo

See
http://weblogs.java.net/blog/ss141213/archive/2005/12/introduction_to.html

On Wednesday 09 June 2010 08:50 AM, glassfish@javadesktop.org wrote:
> I am new in jpa , I try some Jpa example on java application, but when I walk on step more try to test jpa on servlet , I get the problem on create an EntityManagerFactory , It looks like I can't use the some way that I create EntityManagerFactory method like the follow
>
> [b]EntityManagerFactory emf=Persistence.createEntityManagerFactory("MyJPAApplicationPU");
> EntityManager em=emf.createEntityManager();
> try{
> EntityTransaction entr=em.getTransaction();[/b]
> I Google, and find some Thread-safe issuer , any not ideal how to use jpa in servlet .
> any help is appreciate !
> [Message sent by forum member 'newnet']
>
> http://forums.java.net/jive/thread.jspa?messageID=473466
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

newnet
Offline
Joined: 2009-11-03
Points: 0

Thank you Sanjeeb,
may I have two more questions.
1) Can I create the table on the db first then alow the user register by servlet by jpa?
2) Jpa+ servlet /Jpa + ejb what is the advavatage and disadvantage?

Thank you

Sanjeeb Sahoo

On Wednesday 09 June 2010 04:01 PM, glassfish@javadesktop.org wrote:
> Thank you Sanjeeb,
> may I have two more questions.
> 1) Can I create the table on the db first then alow the user register by servlet by jpa?
>
Of course you can. Don't use createtable option during deployment and
ensure that the mapping you specify in the Java code correspond to rdbms
schema.
> 2) Jpa+ servlet /Jpa + ejb what is the advavatage and disadvantage?
>
Take JPA out of equation. Decide if you need to use EJB or not. I am
sure you shall find plenty of good articles on the subject. My short
answer is use EJB in your business layer and use something like JSF/JSP
in your presentation layer.

Sahoo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

newnet
Offline
Joined: 2009-11-03
Points: 0

Dear Sanjeeb,
>Of course you can. Don't use createtable option during deployment
how to do that? do you have an example.
Thank you!

Sanjeeb Sahoo

On Thursday 10 June 2010 07:21 AM, glassfish@javadesktop.org wrote:
> Dear Sanjeeb,
> >Of course you can. Don't use createtable option during deployment
> how to do that? do you have an example.
>
Is that example I earlier pointed to not enough? It creates tables first
and then deploys the app.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net