Home > Java > Hibernate Projections

Hibernate Projections

December 22, 2013 Leave a comment Go to comments

Return dari criteria secara default seluruh object (seluruh property dari object), untuk memperoleh partial object ( satu atau lebih property ) maka digunakan projections. Untuk menggunakan projection, import interface Projections dan class Projection keduanya berada pada paket org.hibernate.criterion. Projection class bersifat final dan semua method-nya static. Berikut ini contoh projection dan table yang digunakan sama dengan table pada post ini.

Criteria criteria = session.createCriteria(People.class);
Projection projection1 = Projections.property("name");
Projection projection2 = Projections.property("job");
ProjectionList pList = Projections.projectionList();
pList.add(projection2);
pList.add(projection1);
criteria.setProjection(pList);
List list = criteria.list();

Iterator iterator = list.iterator();
while(iterator.hasNext()){
Object o[] = (Object[])iterator.next();
System.out.println("Name: "+ o[1]);
System.out.println("Job : "+ o[0]);
}

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: