Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pnowy/nativecriteria
Ultra lightweight lib to generate dynamic SQL based on hibernate session
https://github.com/pnowy/nativecriteria
dynamic-sql hibernate java jpa native-criteria sql
Last synced: 18 days ago
JSON representation
Ultra lightweight lib to generate dynamic SQL based on hibernate session
- Host: GitHub
- URL: https://github.com/pnowy/nativecriteria
- Owner: pnowy
- Created: 2013-02-10T11:42:50.000Z (almost 12 years ago)
- Default Branch: develop
- Last Pushed: 2024-03-10T18:38:03.000Z (8 months ago)
- Last Synced: 2024-10-15T00:54:32.741Z (about 1 month ago)
- Topics: dynamic-sql, hibernate, java, jpa, native-criteria, sql
- Language: Java
- Homepage: http://nativecriteria.przemeknowak.com
- Size: 5.62 MB
- Stars: 36
- Watchers: 6
- Forks: 9
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
![](https://github.com/pnowy/NativeCriteria/workflows/ci/badge.svg)
![](https://github.com/pnowy/NativeCriteria/workflows/documentation/badge.svg)
[![Maven Central](https://img.shields.io/maven-central/v/org.apache.maven/apache-maven.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.github.pnowy.nc%22)### Development && Participation
If you want to participate on the development please perform the pull request to the **develop** branch.
### Documentation
Documentation is available on [http://nativecriteria.przemeknowak.com/](http://nativecriteria.przemeknowak.com/)
### Library available on Maven Central Repository
```xmlcom.github.pnowy.nc
nativeCriteria-core
3.2.0com.github.pnowy.nc
nativeCriteria-spring
3.2.0```
### Simple example:
```java
// 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 cityNames = new ArrayList<>();
while (res.next()) {
resp.add(res.getString("a.city"));
}
```