春天& Hibernate EJB事件 [英] Spring & Hibernate EJB Events

查看:157
本文介绍了春天& Hibernate EJB事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我可以在我的 persistence.xml 中定义这个定义:

 < properties> 
< property name =hibernate.ejb.interceptor
value =my.class.HibernateAuditInterceptor/>
< property name =hibernate.ejb.event.post-update
value =my.class.HibernateAuditTrailEventListener/>
< / properties>

但我想管理 HibernateAuditInterceptor 在spring中使用HibernateAuditTrailEventListener ,所以我可以在这些类中做一些bean注入(例如:session-scoped bean)。这是可能的吗?

解决方案

问题是这些属性只是字符串。即使将SessionFactory定义为Spring bean,通过hibernateProperties设置器传递给它的任何属性也只是字符串:

  ; bean id =mySessionFactoryclass =org.springframework.orm.hibernate3.LocalSessionFactoryBean> 
< property name =dataSourceref =myDataSource/>
< property name =mappingResources>
< list>
< value> whatever.hbm.xml< / value>
< / list>
< / property>
< property name =hibernateProperties>
< value>
hibernate.ejb.interceptor = my.class.HibernateAuditInterceptor
< / value>
< value>
hibernate.ejb.event.post-update = my.class.HibernateAuditTrailEventListener
< / value>
< / property>
< / bean>

所以我不认为你可以这样做。


Is it possible to define a spring-managed EJB3 hibernate listener?

I have this definition in my persistence.xml:

<properties> 
    <property name="hibernate.ejb.interceptor"
        value="my.class.HibernateAuditInterceptor" /> 
    <property name="hibernate.ejb.event.post-update"
        value="my.class.HibernateAuditTrailEventListener" /> 
</properties>

But I would like to manage HibernateAuditInterceptor and HibernateAuditTrailEventListener with spring, so I can do some bean injection (ex: session-scoped bean) within these classes. Is this possible?

解决方案

The problem is that those properties are just strings. Even if you define your SessionFactory as a Spring bean, any properties you pass to it through the hibernateProperties setter are just strings:

<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource"ref="myDataSource"/>
    <property name="mappingResources">
        <list>
            <value>whatever.hbm.xml</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <value>
            hibernate.ejb.interceptor= my.class.HibernateAuditInterceptor
        </value>
        <value>
            hibernate.ejb.event.post-update=my.class.HibernateAuditTrailEventListener
        </value>
    </property>
</bean>

So I don't think you can do that.

这篇关于春天&amp; Hibernate EJB事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆