Last modified by superadmin on 2026/11/25 20:43

Show last authors
1 Take XWiki's database connections from a JNDI data source managed by the [[servlet container>>doc:documentation.xs.admin.installation.deploy-servlet-container.WebHome]], instead of the pool XWiki opens itself from ##WEB-INF/hibernate.cfg.xml##.
2
3 1. Copy the JDBC driver of your [[database>>doc:documentation.xs.admin.installation.install-relational-database.WebHome]] into the library directory of the servlet container rather than into the ##WEB-INF/lib## directory of the XWiki web application, for example ##$CATALINA_HOME/lib## on [[Tomcat>>doc:documentation.xs.admin.installation.deploy-servlet-container.configure-tomcat.WebHome]].
4 1. Declare a data source named ##jdbc/XWikiDS## in the servlet container. On Tomcat, declare it as a resource, either from the Manager web application or in the ##conf/Catalina/<host>/<webapp-name>.xml## file.
5 1. Give that data source the settings XWiki's own pool was providing, since they do not travel with the connections: an isolation level of ##READ COMMITTED##, at least 50 connections and a cache of 20 prepared statements per connection, which are the values XWiki ships in ##WEB-INF/hibernate.cfg.xml##. ##READ COMMITTED## is a requirement rather than a preference: at the ##REPEATABLE READ## that MySQL and MariaDB default to, an XClass saved while a document using it is being loaded is cached as non-existing. The option names are the container's own, and [[Declare an XWiki Data Source in WildFly>>doc:documentation.xs.admin.installation.deploy-servlet-container.configure-wildfly.declare-data-source.WebHome]] and [[Declare an XWiki Data Source in GlassFish>>doc:documentation.xs.admin.installation.deploy-servlet-container.configure-glassfish.declare-data-source.WebHome]] give them for those two.
6 1. Uncomment the ##resource-ref## block of ##WEB-INF/web.xml##, which the WAR ships commented out under "Uncomment if you wish to use a DataSource to define the Database connection". It already declares the same name:(((
7 {{code language="xml"}}
8 <resource-ref>
9 <description>DB Connection</description>
10 <res-ref-name>jdbc/XWikiDS</res-ref-name>
11 <res-type>javax.sql.DataSource</res-type>
12 <res-auth>Container</res-auth>
13 </resource-ref>
14 {{/code}}
15 )))
16 1. Replace the connection settings in your database's block of ##WEB-INF/hibernate.cfg.xml## with the name of that data source, removing the ##hibernate.connection.url##, ##hibernate.connection.username##, ##hibernate.connection.password## and ##hibernate.connection.driver_class## properties. Remove ##hibernate.connection.provider_class## as well: it names XWiki's own pool, which builds its connections from the properties you just deleted and ignores the data source entirely. Keep the ##mapping## elements of the block, which Hibernate needs whatever the connections come from:(((
17 {{code language="xml"}}
18 <property name="hibernate.connection.datasource">java:comp/env/jdbc/XWikiDS</property>
19 <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
20 {{/code}}
21 )))
22 1. Restart the servlet container.
23 1. Verify that XWiki starts and serves its pages, and that the servlet container reports connections being taken from the ##jdbc/XWikiDS## data source.

Get Connected