Issue Details (XML | Word | Printable)

Key: EJB-277
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Norman Richards
Votes: 5
Watchers: 5
Operations

If you were logged in you would be able to see more operations.
z - Hibernate Entity Manager

allow string values for query hints

Created: 16/Mar/07 07:27 PM   Updated: 13/Jan/09 08:25 AM   Resolved: 15/Jan/08 04:44 PM
Component/s: EntityManager
Affects Version/s: None
Fix Version/s: 3.3.2.Beta2

Time Tracking:
Not Specified

File Attachments: 1. XML File components.xml (0.7 kB)
2. Java Source File CustomEntityQuery.java (2 kB)


Participants: Emmanuel Bernard, Nikolai Gagov and Norman Richards


 Description  « Hide

It seems that some string values are not accepted as query hint values in hibernate. In specific, I was trying to convert a simple query that uses setHint("org.hibernate.cacheable", true) to use an XML-defined EntityQuery that uses

<framework:entity-query name="allCategories"
ejbql="select c from Category c"
order="c.name">
<framework:hints>
<key>org.hibernate.cacheable</key>
<value>true</value>
</framework:hints>
</framework:entity-query>

Unfortunately, this fails with an IllegalArgumentException:

Caused by: java.lang.IllegalArgumentException: Value for hint
at org.hibernate.ejb.QueryImpl.setHint(QueryImpl.java:160)
at org.jboss.seam.framework.EntityQuery.createQuery(EntityQuery.java:114)
at org.jboss.seam.framework.EntityQuery.getResultList(EntityQuery.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
...

Although I didn't try it, I would assume this would also fail from a @QueryHint in on a named query since that annotation only accepts a string
value.

I don't think this is technically a bug, but it would be very convenient if all the hints could accept string values.



Emmanuel Bernard added a comment - 22/Mar/07 01:11 AM

@QueryHint will work because the query is a named query.
Are you suggesting to accept string versions for query.setHint()?


Nikolai Gagov added a comment - 13/Jan/09 08:20 AM

Here is also my solution, seems that for some hints Hibernate expects Boolean instead of String, and due to the reason that Seam's entity query acepts hints only as String query.setHints(Map<String, String>), we need to override that..