How to use hibernate in CQ6? | Community
Skip to main content
Level 5
April 28, 2016
Solved

How to use hibernate in CQ6?

  • April 28, 2016
  • 17 replies
  • 14041 views

Hi,

I am using hibernate 4.0.1 for CRUD operations upon page replication. For this i have written eventhandler, in handleEvent method i am writing logic to persist page property in database using hibernate.

I am getting class not found error in hibernate. added all dependencies in POM file, showing all jars in classpath too, bundle is deployed successfully and it is in active state. 

hibernate.cfg.xml i have put in src/main/resources folder and added this folder in classpath.

java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration

Could anyone please help me to resolve the issue, below piece of code is causing the problem 

Configuration configuration = new Configuration().configure();
            ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(
                    configuration.getProperties()). buildServiceRegistry();
            SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
            Session session = sessionFactory.openSession();

 

Thanks,

Pradeep

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Ratna_Kumar

Hi Pradeep,

As Scott stated, the best practice to connect AEM with database is injecting a DataSourcePool.

But Yes, AEM may support hibernate too(http://mvnrepository.com/artifact/org.hibernate/hibernate-osgi), but there is no documentation/community articles related to this topic.

Thanks,
Ratna Kumar.

17 replies

smacdonald2008
Level 10
April 28, 2016

When working with AEM and databases - the best practice is injecting a DataSourcePool - not using Hibernate. 

WHen using a DataSourcePool - you specify the DB properties in the Felix Console config view. 

See this article for more information: 

https://helpx.adobe.com/experience-manager/using/datasourcepool.html

Level 5
April 28, 2016

The problem with data source pool is that we have to write sql queries for all crud operations. In my case we have very complex table structure, so writing sql is very tedious task. If hibernate would have supported in AEM my job will become easy and manageable. I am assuming AEM supports hibernate. Please share some links or examples where hibernate has been used along with AEM.

smacdonald2008
Level 10
April 28, 2016

It may support Hibernate - however - I am not seeing any community articles or documentation that states it does.

Also - I wanted to know why you were not using DataSoucePool - which is best practice.  You answered my question.

I will check within Adobe to see if anyone has examples (assuming it does). 

I will post back my findings. 

Level 5
April 28, 2016

Thanks Donald. 

Ratna_Kumar
Ratna_KumarAccepted solution
Level 10
April 28, 2016

Hi Pradeep,

As Scott stated, the best practice to connect AEM with database is injecting a DataSourcePool.

But Yes, AEM may support hibernate too(http://mvnrepository.com/artifact/org.hibernate/hibernate-osgi), but there is no documentation/community articles related to this topic.

Thanks,
Ratna Kumar.

smacdonald2008
Level 10
April 28, 2016

Some of the AEM people state: 

they can try out the bundle and see what happens. :)

In theory it should work.

Level 2
August 1, 2018

Hi,

Any luck with Hibernate inside the AEM?

Thanks,

Andrii

smacdonald2008
Level 10
August 1, 2018

Database interaction  still has not changed since this thread was created. Using DataSourcePool is still best practice. We have a newer article here:

Adobe Experience Manager Help | Submitting Adaptive Form Data to MySQL using a DataSourcePool

Now there appears to be 3rd party OSGi bundles for this here - Maven Repository: org.hibernate » hibernate-osgi

I have never tried this nor seen any community article that show its usage.

Level 2
August 1, 2018

Hi Scott,

Thanks for the response, I was also not able to find any articles or info how to configure it or at list resolve dependencies for this bundle.

Maybe Pradeep or someone from the community has some experience.

Best regards,

Andrii

fabianh12876403
Level 2
September 17, 2018

this is like bullshit. the Datasourcepool has nothing common with hibernate, it just connect your application with the database.

Why is there no support for config hibernate with AEM CQ?

I think many companies would like to use hibernate with CQ.