Home > Java > Hibernate Criteria Example

Hibernate Criteria Example

December 15, 2013 Leave a comment Go to comments

Criteria hanya digunakan untuk proses SELECT data dari database dan table yang digunakan sama dengan table pada post ini. Sama denga HQL, criteria menggunakan nama class dan property bukan nama table dan column.

Criteria criteria = session.createCriteria(People.class);

Criterion criterion2 = Restrictions.gt("id", 1);
Criterion criterion1 = Restrictions.le("id", 4);
Criterion criterion4 = Restrictions.ilike("name", "Ren%");
Criterion criterion5 = Restrictions.eq("job", "Artist");

Criterion criterion3 = Restrictions.or(criterion4, criterion5);
criteria.add(criterion1);
criteria.add(criterion2);
criteria.add(criterion3);
criteria.addOrder(Order.asc("id"));

List list = criteria.list();

Referensi : dari berbagai sumber.

Semoga bermanfaat.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: