cborm
Install
v3.x
v3.x
  • Introduction
  • Intro
    • Release History
      • What's New With 3.9.0
      • What's New With 3.8.0
      • What's New With 3.7.0
      • What's New With 3.6.0
      • What's New With 3.5.0
      • What's New With 3.4.0
      • What's New With 3.3.0
      • What's New With 3.2.x
      • What's New With 3.1.0
      • What's New With 3.0.0
    • About This Book
    • Author
  • Getting Started
    • Overview
    • Installation
    • Basic Crud - Services
    • Basic Crud - ActiveEntity
  • Base ORM Service
    • Overview
    • Service Properties
    • Concrete Services
    • Service Methods
      • Criteria Queries
        • getRestrictions
        • newCriteria
      • Creation - Population
        • new
        • populate
        • populateFromJSON
        • populateFromQuery
        • populateFromXML
      • Counters
        • count
        • countWhere
        • exists
      • Deleting Entities
        • delete
        • deleteAll
        • deleteByID
        • deleteByQuery
        • deleteWhere
      • Entity Convenience Methods
        • getDirtyPropertyNames
        • getEntityGivenName
        • getEntityMetadata
        • getKey
        • getKeyValue
        • getPropertyNames
        • getTableName
        • isDirty
        • refresh
      • Finders
        • findit
        • findOrFail
        • findByExample
        • findWhere
        • findAll
        • findAllWhere
      • Getters
        • get
        • getOrFail
        • getAll
      • ORM Session
        • clear
        • evict
        • evictCollection
        • evictQueries
        • getSessionStatistics
        • isSessionDirty
        • merge
        • sessionContains
      • Querying
        • executeQuery
        • list
      • Saving Entities
        • save
        • saveAll
      • Utility Methods
        • autoCast
        • createService
        • idCast
        • nullValue
        • when
    • Dynamic Finders- Counters
      • Method Signatures
      • Method Expressions
      • Query Options
    • Automatic Java Types
  • Virtual Services
    • Overview
    • Service Properties
    • Concrete Virtual Services
  • Active Record
    • Active Entity Overview
    • Constructor Properties
    • Usage
    • Validation
  • Criteria Queries
    • Criteria Builder
      • Getting Started
      • Restrictions
        • Value Casting
        • SQL Restrictions
      • Modifiers
      • Results
      • Associations
      • Projections & Aggregates
    • Detached Criteria Builder
      • Getting Started
      • Projections
      • Subqueries
      • DetachedSQLProjection()
      • Criterias
      • Associations
    • Help! I'm Not Getting the Result I expected!
  • Advanced Features
    • Automatic REST Crud
    • Hibernate Logging
    • Mementifier
    • ORM Events
      • Custom Event Handler
    • Unique Property Validation
Powered by GitBook
On this page
  • Query Modifiers
  • Result Modifiers

Was this helpful?

Edit on Git
Export as PDF
  1. Criteria Queries
  2. Criteria Builder

Modifiers

Query Modifiers

The following methods alters the behavior of the executed query, some can be a life saver, so check them all out.

Method

Description

cache(boolean cache=true, cacheRegion)

Tells Hibernate whether to cache the query or not (if the query cache is enabled), and optionally choose a cache region

cacheRegion(cacheRegion)

Tells Hibernate the cache region to store the query under

comment(comment)

Add a comment to the generated SQL.

fetchSize(numeric fetchSize)

Set's the fetch size of the underlying JDBC query

firstResult(numeric firstResult)

Specifies the offset for the results. A value of 0 will return all records up to the maximum specified.

maxResults(numeric maxResults)

Set a limit upon the number of objects to be retrieved.

order(property,sortDir='asc',ignoreCase=false)

Specifies both the sort property (the first argument, the sort order (either 'asc' or 'desc'), and if it should ignore cases or not

peek( target )

Peek into the criteria build process with your own closure that accepts the criteria itself.

queryHint(hint)

Add a DB query hint to the SQL. These differ from JPA's QueryHint, which is specific to the JPA implementation and ignores DB vendor-specific hints. Instead, these are intended solely for the vendor-specific hints, such as Oracle's optimizers. Multiple query hints are supported; the Dialect will determine concatenation and placement.

readOnly(boolean readOnly)

Set the read-only/modifiable mode for entities and proxies loaded by this Criteria, defaults to readOnly=true

timeout(numeric timeout)

Set a timeout for the underlying JDBC query in milliseconds.

when( test, target )

A nice functional method to allow you to pass a boolean evaulation and if true, the target closure will be executed for you, which will pass in the criteria object to it.

c.timeout( 5000 )
c.readOnly(true)
c.firstResult(20).maxResults(50).fetchSize(10).cacheRegsion('my.awesome.region')
c.cache(true,'my.region')
c.order('lastName','desc',true);

newCriteria()
	 .eq( "this", value )
	 .peek( function(criteria){
	 	systemOutput( "CurrentSQL: #criteria.getSQLLog()#" )
	 })
	 .when( !isNull( arguments.published ), function( c ){
		c.eq( "isPublished", published )
	 })
	 .list();

Result Modifiers

You can also tell Hibernate to transform the results to other formats for you once you retrieve them.

  • asDistinct() - Applies a result transformer of DISTINCT_ROOT_ENTITY

  • asStruct() - Applies a result transformer of ALIAS_TO_ENTITY_MAP so you get an array of structs instead of array of objects

  • asStream() - Get the results as a CBstream

PreviousSQL RestrictionsNextResults

Last updated 5 years ago

Was this helpful?