18 octubre 2009

Hibernate - Query Hints

3.4.1.7. Query hints


Query hints (for performance optimization, usually) are implementation specific. Hints are declared using the query.setHint(String name, Object value) method, or through the @Named(Native)Query(hints) annotation Note that these are not SQL query hints! The Hibernate EJB3 implementation offers the following query hints:

Table 3.1. Hibernate query hints

HintDescription
org.hibernate.timeoutQuery timeout in seconds ( eg. new Integer(10) )
org.hibernate.fetchSizeNumber of rows fetched by the JDBC driver per roundtrip ( eg. new Integer(50) )
org.hibernate.commentAdd a comment to the SQL query, useful for the DBA ( e.g. new String("fetch all orders in 1 statement") )
org.hibernate.cacheableWhether or not a query is cacheable ( eg. new Boolean(true) ), defaults to false
org.hibernate.cacheModeOverride the cache mode for this query ( eg. CacheMode.REFRESH )
org.hibernate.cacheRegionCache region of this query ( eg. new String("regionName") )
org.hibernate.readOnlyEntities retrieved by this query will be loaded in a read-only mode where Hibernate will never dirty-check them or make changes persistent ( eg. new Boolean(true) ), default to false
org.hibernate.flushModeFlush mode used for this query
org.hibernate.cacheModeCache mode used for this query

The value object accept both the native type or its string equivalent (eg. CaheMode.REFRESH or “REFRESH”). Please refer to the Hibernate reference documentation for more information.

No hay comentarios: