Confluence Macro Database

Jan Kueck February 25, 2015

Hello everyone,

i have to develop a confluence macro for our buisness. The macro should display some customer data in relation to their installed products. That the reason why we use an external database (postgres).

We attempt to develop the macro with hibernate. We test to different ways:

  • Hibernate with hiberante.cfg.xml

Here we can read the hibernate.cfg.xml but we can not  instatiate a configuration object because there are some library conflicts with confluence. And there are the problem that the configuration object can not read correctly the hibernate.cfg.xml close to the <mapping class="xxx.xxx.xxx.User">.

URL hibernateFileURL = ClassLoaderUtils.getResource("hibernate.cfg.xml", this.getClass());

Configuration configuration = new Configuration().configure(new File(hibernateFileURL.toURI()));
SessionFactory sessionFactory = configuration.buildSessionFactory();
Session session = sessionFactory.openSession();

 

  • Hibernate with JPA

Here we try to instantiate the entitymanager and there are some problems because the entity manager can not find the required persitence.xml. The persistence.xml ist located under resources/META-INF/.., the normal location.

EntityManager entityManager = Persistence.createEntityManagerFactory("XX").createEntityManager();

 

So my question is: can i connect my confluence macro to an external database with hibernate or jpa? Or can i connect to the internal confluence database add some tables and work with these?

There is an valid general way to do something like this?

 

I use confluence ATLAS Version: 5.0.13, all dependencies are the actuals from maven.

 

I hope there are some helpful answers.

Greetz Jan Kueck

 

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Steve Gerstner [bridgingIT]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 25, 2015

The valid general way is called Active Objects, it's like Hibernate an ORM-mapper, but much simpler:

https://developer.atlassian.com/docs/atlassian-platform-common-components/active-objects/getting-started-with-active-objects

Regards

Steve

Jan Kueck February 25, 2015

Thanks for the fast reply! Yeah, I worked a bit with AO but not very deep, I will learn to work with it.. But one question. Can I use AO for a connection to an external database, only for the connection to the confluence database or to use for both? Thanks! :)

Steve Gerstner [bridgingIT]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 25, 2015

I think, you can use it for both scenarios...

TAGS
AUG Leaders

Atlassian Community Events