hati-hati juga, karena yg di-return service itu masih model Hibernate, ada kemungkinan kena LazyLoadingException, waktu manggil method getter dari Customertype. kalau Customertype adalah model Hibernate, kesalahan itu bisa terjadi.
default setting hibernate menggunakan lazy loading, jadi kalau session ditutup, lalu model di-return, lazy loading akan gagal. cara untuk menghindari ini, bisa dengan copy object ke valueobject, dari List<Customertype> jadi List<CustomertypeVO>, atau dengan mematikan fitur lazy loading. -o--o---( ^ ^ )---o--o- And e-sau said, Behold, I am at the point to reboot: and what profit shall this public/private key certificate do to me? Daniel Baktiar (http://danielbaktiar.com) On 6 April 2010 22:37, Ifnu bima <ifnub...@gmail.com> wrote: > > > > public class CustomerTypeService { > > private SessionFactory sessionFactory = > HibernateUtil.getSessionFactory(); > > private Session session = sessionFactory.openSession(); > > > > public List<Customertype> getCustomertypes() throws SQLException, > Exception{ > > return session.createCriteria(Customertype.class).list(); > > } > > } > > Buka tutup sessionya ada di method-nya service. Ga boleh session > dibuka terus tapi ga ditutup2 > > > public List<Customertype> getCustomertypes() throws SQLException, > Exception{ > Session session = sessionFactory.openSession(); > List<Customertype> customers = > > session.createCriteria(Customertype.class).list(); > session.close(); > return customers; > } > > -- > > regards > > >