• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Shiro Hibernate Tomcat - how to unify datasources using JNDI from Hibernate

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Questions are marked bold below. This is the context of the question:

Shiro wants a JNDI datasource:


so I configured it one in Tomcat:


however, I'm using another setup from hibernate for my application:


This is also necessary in web.xml for the line in hibernate.cfg.xml:


I think I'm using two separate datasources, aren't I?Is that bad? Because I can't tell wether I'm using one PooledDataSource or two at the moment... Everything looks fine, except I think I will run into connection problems or the datasource registered in JNDI because it's not properly set with c3p0... also need to confirm this is a proper setup for this scenario.

What I want, is to register the hibernate datasource in JNDI to use it with Shiro, in common with the rest of my application. How do I do that? Is there any chance the configuration I'm using treats both datasources with the same c3p0 configuration, or maybe it sees the two datasources as one? Hopeful thinking...

Logs indicate there's two separate data sourcepools registering:
One at start, immediately after "INFO: Initializing Shiro environment", probably the tomcat configured one:


and the other later(s!?) when application calls on it, probably the hibernate one:


but afterwards there's a lot of pools initializing:

This is from the datasource configured in tomcat


this seems related to the initial settings of c3p0 in hibernate.cfg.xml


then on a short distance this appears:

... probably a separate thread and connection/settings for caching statements? hmm...

then another initialization


and afterwards, when there's idle checks, only one triggers according to settings:


meaning the other one will run into problems after the 8 hours set by mysql wait_timeout of 28800 seconds (in fact that's exactly what happened if I think about it, because authorization/authentication failed ...can't tell if the application crapped out too because everything was behind Shiro, anyway, enabling c3p0 for the hibernate connection will not enable it for Shiro datasource too...)

EDIT: In the meantime I discovered this, for Tomcat 7 (lucky me if it works):
http://people.apache.org/~fhanik/jdbc-pool/jdbc-pool.html

EDIT2: EDIT doesn't work, there's some bug going on that was patched supposedly but can't get it to work.
Anyway, that's for a JDBC pooled datasource. For a com.mchange.v2.c3p0.ComboPooledDataSource there's
http://www.mchange.com/projects/c3p0/

still, it would be nice if I could register the hibernate datasource in JNDI...
 
Tudor Raneti
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's hibernate.jndi property to be set but I haven't the time to get into that now... dunno if that's the answer.
For some reason the other people that asked the same question didn't make use of this option.
 
Poop goes in a willow feeder. Wipe with this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic