membuat native query pada hibernate dan return list object

Native Query pada Hibernate dan nge-return list object, ::

q> Teknologi yang dipake masih tetep zk + hibernate + spring
q> Class yang digunakan adalah org.hibernate.SQLQuery
q> Langsung ke coding bro

@SuppressWarnings("unchecked")
@Override
@Transactional(readOnly=true)
public List<Mstmenu> getListMenuByUser(String user){
String st = "select mm.* from MSTROLEACCESS mra " +
" join MSTMENU mm on mm.VMENUID = mra.VMENUID " +
"join MSTROLE mr on mr.VROLEID = mr.VROLEID " +
" where mr.USER = :user and mra.VSTATUS = 'A' " +
"order by mm.vparent,mm.norderer asc";

SQLQuery sq = getHibernateTemplate().getSessionFactory().getCurrentSession()
.createSQLQuery(st);
sq.setString("user", user);
sq.addEntity(Mstmenu.class);

List<Mstmenu> list = sq.list();
return list;
}

q> Tinggal panggil method getListMenuByUser(String user), dengan parameter user dan akan nge-return List<Mstmenu>

q> Wow

Selamat ber-hibernate

sumber ::
http://www.tutorialspoint.com/hibernate/hibernate_native_sql.htm

Published by

saifiahmada

Begin a big Process with a bit trying

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