How to access custom tables added to confluence schema using Hibernate

Hello Atlassian,

We are upgrading our confluence server from V5.8.13 to V6.6.2. We found that confluence has upgraded the hibernate version2 to version5 because of this we are facing some difficulties for accessing our custom tables.

In confluence V5.8.13 we used to add custom.hbm.xml mapping configurations to the existing confluence hibernate configuration by editing the hibernate session factory.

import com.atlassian.spring.container.ContainerManager;
import bucket.core.persistence.hibernate.ConfigurableLocalSessionFactoryBean;
import net.sf.hibernate.SessionFactory;

ConfigurableLocalSessionFactoryBean localSessionFactoryBean =(ConfigurableLocalSessionFactoryBean)ContainerManager.getInstance().getContainerContext().getComponent("&tenantedLocalSessionFactoryBean");
SessionFactory sf = (SessionFactory) localSessionFactoryBean.getObject();

Using reflection we were able to access all the fields and methods to modify the namedQueries and ClassPersisters and hibernate configurations dynamically.

Field classPersistersField = sessionFactory.getClass().getDeclaredField(“classPersisters”);

In confluence V6.6.2 the hibernate version is been upgraded to V5.
We are facing difficulties with the upgraded hibernate version, can you please help how to dynamically map our custom.hbm.xml configurations and access the custom tables using the hibernate session.


I would highly recommend switching to activeobjects or use an alternate database for these tables m. If you’re adding custom tables like this you won’t be participating in any backups/restore and will have a painful experience each upgrade.


Just to clarify, Daniel’s suggestion on ActiveObjects is the official Atlassian position. I realize it is a big change. However, it is important for overall Jira supportability. In addition to the backup/restore issue Daniel pointed out, there’s an element of “plugin tenancy” – that plugins should work like microservices and “own” their data. ActiveObjects makes that possible in a way that direct database access cannot.

From a dev support perspective, it also changes things here. Using the recommended ActiveObjects means we have a better chance of answering your questions, using Atlassian documentation. With Hibernate, you’re better off going to the Hibernate community itself, simply because so few of us use it directly.


Hello @ibuchanan / @daniel ,
Thanks for the reply.I have following questions.

  1. If we use ActivityObjects , will it create seperate sessionFactory instance for this plugin or does it uses sessionFactory instance confluence uses under the covers?
  2. Is there a chance for it to give any performance issues?
  3. Also will it help to create those tables through plugin configuration in admin console?


  1. It uses whatever the host application tells it to use. :slight_smile: Its an abstraction layer so the app itself doesn’t have to deal with that. It more than likely uses the host app connection pool.
  2. Everything will give you a performance problem depending on how you use it. :wink: If you’re using it in a straight forward manner though you should be good (don’t do huge queries -rather use .stream() )
  3. Not sure what you mean here. Can you expand?

Thanks Daniel. Let me rephrase the last question. My question is whether this activeobjects helps creating tables for new entities we implement or does it only support to query existing tables?

Oh in that case - it manages all of the tables for you. If you remove the entity - the table is gone. If you remove a column - it’s gone.

General rule of thumb: don’t remove - always add. That way you don’t lose content. If you do need to remove (to remove tech debt) - do it at major revs and communicate to your customers so that they know that they have to pause at that particular version.

Thanks @daniel, After using AO we are facing these issues

1)How to use a custom sequence with custom primary key in oracle 11
How can we use the existing sequence (“SEARCHACTIVITYIDSEQ”) and custom primary key(“SEARCHACTIVITYID”) when we create AO Entity.

public interface SearchActivityEntity extends Entity{
public long getSEARCHACTIVITYID();

2)How to access the existing tables using AO
We have a existing Table “SEARCHACTIVITY”, is there any way to access these existing tables with AO?
AO creates the new table (“AO_707237_SEARCHACTIVITY” even if we specify the existing table name

public interface SearchActivityEntity extends Entity{

Thanks for the reply @ibuchanan