Using tomcat connection pool with JPA

I want to use the connection pool with JPA / TopLink in my web application running on tomcat.Earlier I use jdbc Connection and Statement classes to manage data in the database; to use the connection pool this way I simply declare the resource in context.xml and get this resource in the application:

Context c = new InitialContext();
DataSource source = (DataSource) ((Context)c.lookup("java:comp/env")).lookup("jdbc/MySource");

And now I want to use such a connection pool with JPA. How can i do this?

One more question: in some examples I saw that reosurce is declared in the context of .xml, and then it is declared in web.xml in <Resource-ex>. Why should I declare it in different places or is it the same ad, I mean, is this the equivalent of an ad in the .xml context?

+3
source share
1 answer

And now I want to use such a connection pool with JPA. How can i do this?

, <Resource> context.xml, JPA webapp /META-INF/persistence.xml.

<persistence-unit name="YourPersistenceUnit" transaction-type="JTA">
    <jta-data-source>jdbc/MySource</jta-data-source>
</persistence-unit>

: , reosurce context.xml, web.xml <resource-ref>. , , context.xml?

<Resource> context.xml servletcontainer. webapps. <resource-ref> web.xml webapp. : JPA web.xml. persistence.xml.

+6

All Articles