Skip to main content
Level 5
Apr 28, 2016 12:03 PM UTC
Solved

How to use hibernate in CQ6?

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.
Ratna_Kumar
Ratna_KumarAccepted solution
Level 10
Apr 28, 2016 3:45 PM UTC

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
Apr 28, 2016 12:31 PM UTC

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

Translate
Level 5
Apr 28, 2016 2:11 PM UTC

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.

Translate
smacdonald2008
Level 10
Apr 28, 2016 2:40 PM UTC

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. 

Translate
Level 5
Apr 28, 2016 3:30 PM UTC

Thanks Donald. 

Translate
Ratna_Kumar
Ratna_KumarAccepted solution
Level 10
Apr 28, 2016 3:45 PM UTC

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.

Translate
smacdonald2008
Level 10
Apr 28, 2016 3:47 PM UTC

Some of the AEM people state: 

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

In theory it should work.

Translate
Level 2
Aug 1, 2018 1:53 PM UTC

Hi,

Any luck with Hibernate inside the AEM?

Thanks,

Andrii

Translate
smacdonald2008
Level 10
Aug 1, 2018 1:59 PM UTC

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.

Translate
Level 2
Aug 1, 2018 2:08 PM UTC

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

Translate
fabianh12876403
Level 2
Sep 17, 2018 8:21 AM UTC

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.

Translate