Git Product home page Git Product logo

hibernate-mysql-criteria's Introduction

hibernate-mysql-criteria

A Simple Hibernate MySQL example explaining the Criteria API

Criteria - helps to build nested and structured query in java (not possible with HQL or SQL)… compile time syntax checking… performance issue coz generated query is slow… maintanence issue - queries scattered through java code and code becomes very difficult to understand

Criteria criteriaObj = sessionObj.createCriteria(Employee.class);

Restrictions - allows user to add restrictions like eq, ne, like, illike(case sensitive), MatchMode(ANYWHERE, END, EXACT, START) on the string, isNull, isNotNull, ge, get, it, le

Criterion - is actually a restriction defined in a criteria object

Criteria criteriaObj = sessionObj.createCriteria(Employee.class);

criteriaObj.add(Restrictions.eq("employeeId", 220L));

criteriaObj.addOrder(Order.desc("employeeId"));

List empDetail = criteriaObj.list();

LogiCalExpression - used to combine two same criterion (like OR)

DisJunction - used to combine more than two different criterion (like OR)

Conjunction - used to combine more than two different criterion (but like AND)

SqlRestriction - used to specific directly in the sql statement (crit.add(Restrictions.sqlRestriction("{alias}.description like 'Mou%'"));)

Pagination - getFirstResult() - integer represents the first row of the result set, getMaxResult() - integer until which you want the records to be fetched

UniqueResult - if you want to obtain a single Object entity instead of list…. If more than one result comes up throws hibernateException… works like Map result in JDBC

Distinct Result - DISTINCT like queries

Sorting - Order.desc() or Order.asc()

Projection - provides aggregate functions like avg(), max(), min(), sum(), count() countDistinct()

QueryByObject - instead of build query with criterion object, you can create criteria by using entity object by partial filtering

hibernate-mysql-criteria's People

Contributors

gopikrishhnachokkalamani avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.