Ultra lightweight lib to generate dynamic SQL based on hibernate session
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
gradle
nativeCriteria-core
nativeCriteria-spring
nativeCriteria-test
.editorconfig
.gitignore
.travis.yml
README.md
RELEASE.md
build.gradle
deploy_docs.sh
gradlew
gradlew.bat
package.json
settings.gradle
yarn.lock

README.md

Build Status Maven Central Sputnik

Development && Participation

If you want to participate on the development please perform the pull request to the develop branch.

Documentation

Documentation is available on https://pnowy.gitbooks.io/nativecriteria/content/

Library available on Maven Central Repository

<!-- core module -->
<dependency>
    <groupId>com.github.pnowy.nc</groupId>
    <artifactId>nativeCriteria-core</artifactId>
    <version>3.0.0</version>
</dependency>

<!-- spring integration module -->
<dependency>
    <groupId>com.github.pnowy.nc</groupId>
    <artifactId>nativeCriteria-spring</artifactId>
    <version>3.0.0</version>
</dependency>

Simple example:

// SELECT a.city FROM address a WHERE a.zip_code IS NULL AND city := ? ORDER BY a.city ASC
NativeCriteria nc = new NativeCriteria(new JpaQueryProvider(entityManager), "address", "a")
      .setProjection(NativeExps.projection().addProjection("a.city"))                       
      .add(NativeExps.isNull("a.zip_code"));                                                
      .setOrder(NativeExps.order().add("a.city", OrderType.ASC));

// dynamic where part
if (StringUtils.isNotEmpty(city)) {
    nc.add(NativeExps.eq("a.city", city))
}            
      
// get the results
CriteriaResult res = c.criteriaResult();                                                    
List<String> cityNames = new ArrayList<>();
while (res.next()) {                                                                        
   resp.add(res.getString("a.city"));                                                       
}