aspose file tools*
The moose likes Tomcat and the fly likes jpa, datasource and tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "jpa, datasource and tomcat" Watch "jpa, datasource and tomcat" New topic
Author

jpa, datasource and tomcat

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
I use JPA(Hibernate) and have a persistence.xml and a context.xml bound to my database - all works well.

However, in the documentation I found that I have also declare the resource-ref in web.xml:


But I have not declare it, and it s working. So my question:

Do I have to declare the resource-ref, when having a persistence.xml already?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

The resource-ref connects your webapp to the Tomcat connection pooler. It establishes the JNDI name of the datasource object (java:/comp/env/jdbc/mt\yDataSource).

However, if you use a brute-force JPA implementation, it will create its own connection manager within the webapp, so this object will not be referenced.

That's not entirely a good idea, since it's often desirable to manage resources at the server level, but there's nothing otherwise wrong with it.

Myself, I'm using Spring to manage JPA and I have Spring configured to get the persistence parameters from the JNDI definition, but it's a bit more complicated that way. On the other hand, because I'm using the external pool, I can switch from test to production databases without changing persistence.xml, web.xml, recompiling any classes or rebuilding the WAR. I manage everything from the external Tomcat definitions for the test/production server.


Customer surveys are for companies who didn't pay proper attention to begin with.
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
hello,

so is it better to provide additionally this information in my web.xml?:



The problem is, when I provide the above information, then I get this error:



I use mySQL and have definitly the lib "mysql-connector-java" in the tomcat-lib-folder (not in the applications web-inf/lib).

When I do NOT provide the resource-ref-information, then I get NO errors and all works.

Do you know, what is wrong?

(Maybe the DBCP of tomcat and the use of Hibernate JPA? I guess, Hibernate has its own (better?) connection pool?)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jpa, datasource and tomcat