Using Hibernate Profiler with Grails

98 views
Skip to first unread message

Jon Palmer

unread,
Nov 3, 2012, 9:49:39 PM11/3/12
to hibernate...@googlegroups.com
Does anyone have any experience using the Hibernate Profiler with a Grails app?

I've been trying to figure out how to configure the profiler through log4j or Spring I'm struggling to map the instructions to the Grails configuration DSLs.

Any advice would be appreciated.
Thanks
Jon

Oren Eini (Ayende Rahien)

unread,
Nov 3, 2012, 9:52:50 PM11/3/12
to hibernate...@googlegroups.com
You can just call HibernateProfiler.initialize(); in the beginning of the app.

Jon Palmer

unread,
Nov 3, 2012, 10:54:29 PM11/3/12
to hibernate...@googlegroups.com
That seems to work in Bootstrap.groovy. Not sure if there is a better place.

However, with that configuration I don't get query parameters and values in the profiler. How can that be configured?

Do you have any advice as to how to add the listener to get Urls associated with the sessions?

Thanks
Jon

Oren Eini (Ayende Rahien)

unread,
Nov 4, 2012, 1:30:32 AM11/4/12
to hibernate...@googlegroups.com

If you are not using Spring, then you can configure the profiler directly by modifying the Hibernate configuration. The following properties should be set in your Hibernate configuration file:

<session-factory>
    ...
    <property name="cache.query_cache_factory">
    hibernatingrhinos.hibernate.profiler.cache.ProfilerQueryCacheFactory
    </property>
    <property name="generate_statistics">true</property>
</sessionFactory>

If you have defined the property jdbc.batch_size to a number greater than zero, then you should also define the following property:


<session-factory>
    ...
    <property name="jdbc.batch_size">50</property>
    <property name="jdbc.factory_class">
        hibernatingrhinos.hibernate.profiler.jdbc.ProfilerBatchingBatcherFactory
    </property>
</session-factory>

Jon Palmer

unread,
Nov 4, 2012, 7:44:00 AM11/4/12
to hibernate...@googlegroups.com
Thanks, I had previously read that. The challenge I have is that Grails IS using spring under the covers. Except it provides various DSL wrappers on top of the various configuration xml files. With just HibernateProfiler.initialize(); in the right place most things work. However, I don't get query parameters in the profiler. Any help would be appreciated.

Thanks
Jon

Oren Eini (Ayende Rahien)

unread,
Nov 4, 2012, 3:53:31 PM11/4/12
to hibernate...@googlegroups.com
You have to have some way with Grails to setup the hibernate configuraiton, then you just need to set those  values there.

Jon Palmer

unread,
Nov 4, 2012, 5:05:56 PM11/4/12
to hibernate...@googlegroups.com
I can get access to the sessionFactory and I'm sure I can set properties on it there. However, I'm struggling to figure out what properties I need to set. the 'How to use.txt' suggests adding this to the sessionfactory bean:


<bean id="sessionFactory" 
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
...
    <property name="hibernateProperties">
        <props>
        ...
        </props>
    </property>
    <hprof:profiler />
</bean>

where hprof is given by the namespace: http://www.nhprof.com/schema/hprof/hprof.xsd which redirects. If I have programmatic access to the sessionFactoy bean what properties should I add that are equivalent to the <hprof:profiler/> tag in the xml?

Thanks
Jon

Oren Eini (Ayende Rahien)

unread,
Nov 4, 2012, 6:53:02 PM11/4/12
to hibernate...@googlegroups.com
Do you have access the the Configuration object?
you need to call cfg.setProperty("cache.query_cache_factory", "hibernatingrhinos.hibernate.profiler.cache.ProfilerQueryCacheFactory")
Reply all
Reply to author
Forward
0 new messages