-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Filter. Undefined parameter name. I think it's right.
PostPosted: Tue May 05, 2009 3:39 pm 
Beginner
Beginner

Joined: Fri Dec 10, 2004 11:46 pm
Posts: 37
Hi I'm reading the Hibernate Persistence book and trying to implement filters on my application. Everything seems right, but I can't seem to get it working. Everything else works file except when trying to set the filter parameter. Any ideas?

Hibernate: 3.1.3

hibernate.cfg.xml:

<hibernate-configuration>
<session-factory>
...
<mapping resource="com/mycom/DynamicFilters.hbm.xml"/>
<mapping resource="com/mycom/MyClass.hbm.xml"/>
...
</session-factory>
</hibernate-configuration>

DynamicFilters.hbm.xml:

<hibernate-mapping>

<filter-def name="limitByName">
<filter-param name="name" type="String" />
</filter-def>

</hibernate-mapping>

MyClass.hbm.xml:

<hibernate-mapping>

<class name="com.mycom.MyClass" table="`MY_CLASSES`"
dynamic-insert="true" dynamic-update="true">

...

<property name="name" column="`NAME`" />

<filter name="limitByName" condition=":name = NAME"/>

</class>

</hibernate-mapping>


In the code:

HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();

Filter filter = HibernateUtil.getSessionFactory().getCurrentSession().enableFilter("limitByName");
filter.setParameter("name", "John");


Top
 Profile  
 
 Post subject: Re: Filter. Undefined parameter name. I think it's right.
PostPosted: Wed May 06, 2009 6:15 am 
Newbie

Joined: Wed Jan 28, 2009 9:57 am
Posts: 16
Location: Leinfelden, Germany
The mappings look good.
How are you trying to retrive this MyClass Entity?
Filter would be applicable only on HQL and criteria querries. Retrieval by identifier can’t be restricted with a dynamic data filter.


Top
 Profile  
 
 Post subject: Re: Filter. Undefined parameter name. I think it's right.
PostPosted: Wed May 06, 2009 8:22 am 
Beginner
Beginner

Joined: Fri Dec 10, 2004 11:46 pm
Posts: 37
Thanks but...

Anyhow, the problem is the parameter type. I know use string (lower case) not String


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.