I need to use the Hibernate´s FilterDef and Filter annotations on my
EntityBean. I configured the annotations but I couldn´t figure out the right
moment to enable it because the EntityManager´s HibernateSession is always a
different instance. I´m using a Stateless Session Bean.
For example, when I get the EntityManager in the first time, I get its
HibernateSession and enable the filter, and this filter doesn´t exists in the
next time I get the same EntityManager in the same SessionBean.
I mean, the HibernateSession that had the filter was lost and I have to enable
it again if I want the filter to work in the same EntityManager instance.
The EntityBean and its annotations:
| @Entity(access = AccessType.FIELD)
| @Table(name = "SOME_OTHER_TABLE")
| @FilterDef(name="FilterDomain", [EMAIL PROTECTED](name="param1"
type="string")})
| @Filters({
| @Filter(name="FilterDomain", condition="RV_MEANING is not null and
RV_LOW_VALUE <> :param1")
| })
| public class Dominio {
| ...
| }
|
The SessionBean and the accessor method to get the EntityManager:
| @Stateless
| public abstract class AbstractController {
| @PersistenceContext(unitName="MyContext",
type=PersistenceContextType.TRANSACTION)
| private EntityManager em;
|
| public EntityManager getEM() {
| //code to enable the EntityBean´s filters
| EMUtil.enableFilters(this.em);
| return this.em;
| }
| }
|
The Utility class to enable the filters:
| public class EMUtil {
| public static void enableFilters(EntityManager em) {
| Session session = ((HibernateSession)em).getHibernateSession();
| Filter filter = session.getEnabledFilter("FilterDomain");
| if (filter == null) {
| //always get into the if, the filter must be enabled every time.
| filter = session.enableFilter("FilterDomain");
| filter.setParameter("param1", "A");
| }
| }
| }
|
I tried to use the javax.ejb.PostConstruct annotation and enabled the filter
there, but I get a javax.persistence.TransactionRequiredException that tells me
the EntityManager must be access within a transaction. And considering my
problem, I believe it would happen the same with the HibernateSession.
Does anyone have an idea or example where I can use the Hibernate´s Filter
annotation without enabling it in the HibernateSession every time I need to use
the EntityManager?
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3912319#3912319
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3912319
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user