Home > Java > HQL Sample

HQL Sample

December 15, 2013 Leave a comment Go to comments

Berikut ini example HQL  dan table yang digunakan sama dengan table pada post ini.

1. Example HQL select query

Query query=  session.createQuery("from People where id >:idPeople");
query.setParameter("idPeople",3);
List list = query.list();

2. Example HQL update query

query=  session.createQuery("update People set name= :namePeople, address.addressStreet =:addressStreetPeople, address.addressCity =:addressCityPeople, address.addressZipcode =:addressZipcodePeople  where id =:idPeople");
query.setParameter("namePeople", "Renata Putri");
query.setParameter("addressStreetPeople", "Taman Sari");
query.setParameter("addressCityPeople", "Bandung");
query.setParameter("addressZipcodePeople", "34599");
query.setParameter("idPeople",3);

query.executeUpdate();

3. Example HQL delete query

query=  session.createQuery("delete People where id >:idPeople");
query.setParameter("idPeople",3);
query.executeUpdate();

3. Example HQL insert query

Pada HQL tidak support INSERT INTO ( ) VALUES ( ) statement.

Semoga bermanfaat.

Referensi : dari berbagai sumber

  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: