views:

454

answers:

2

How can you add greater than or less than symbols to the condition on a Hibernate filter specified in the hbm.xml file?

I am trying to add a filter to limit the collection to a specific date range:

<filter name="limitTalksByDateRange" condition="talkstart >= :tstart and talkstart <= :tend" />

Unfortunately this breaks the XML parsing. I've tried backslash-escaping, "ge" and "le" and even "between :tstart and :tend" which is mentioned in the Hibernate documentation. None has worked, and I'll be damned if I can find any documentation whatsoever that specifically delineates the valid operators in the filter condition.

+1  A: 

Did you try:

<filter name="limitTalksByDateRange" condition="talkstart &gt;= :tstart and talkstart &lt;= :tend" />

Note the &gt; and &lt; instead of the > and <.

Also, the examples that I saw did not have the ':' on the limit variables, so perhaps this:

<filter name="limitTalksByDateRange" condition="talkstart &gt;= tstart and talkstart &lt;= tend" />

or this:

<filter name="limitTalksByDateRange" condition="talkstart BETWEEN tstart and tend" />

would work better.

Michael Myers
A: 

I've found that this works:

<filter name="limitTalksByDaterange" condition="talkstart &#62;= :tstart and talkstart &#60;= :tend" />

I think the #nn codes might be a bit more reliable; I've seen &gt and &lt break in certain contexts.

I wasn't able to make the between construct work at all.

cholli2