Scott Basinger has provided a helpful modification to EntityQuery to allow easy use of the 2nd level cache.
This seems an ideal candidate to make it into future Seam releases - are there any objections from the Seam devs?
Mods to EntityQuery createQuery method are:
if (getHints() != null) { for (Map.Entry<String, Object> me : getHints().entrySet()) { if (me.getValue() instanceof String) query.setHint(me.getKey(), me.getValue()); else if (me.getValue() instanceof Boolean) { Boolean value = (Boolean) me.getValue(); query.setHint(me.getKey(), value.booleanValue()); } else { throw new UnsupportedOperationException( "Query hint of type " + me.getValue().getClass() + " not supported."); } } }
which then allows:
public MyQuery() { setEjbql(EJBQL); setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS)); getHints().put("org.hibernate.cacheable", Boolean.TRUE); }