Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

jpa, datasource and tomcat

 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Saloon Keeper
Posts: 25461
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?)
 
To do a great right, do a little wrong - shakepeare. twisted little ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic