Ini adalah koleksi masalah yang ditemui semasa menggunakan Spring dan Hibernate beserta cara penyelesaian yang Tedi gunakan, untuk menjadi panduan pada masa akan datang kerana kesilapan bisa berlaku berulang-kali.

Masalah #1 : No Session found for current thread : org.hibernate.HibernateException: No Session found for current thread.

Penyelesaian:

Tambah @Transactional pada service. Punca masalah ialah tiada @Transactional pada service.

Masalah #2: unexpected token: AS near line 1

Punca: tersilap letak AS sebelum nama column.

Masalah #3: query specified join fetching, but the owner of the fetched association was not present in the select list.

Penyelesaian: Use regular join instead of join fetch (by the way, it's inner by default): As error message tells you, join fetch doesn't make sense here, because it's a performance hint that forces eager loading of collection.

Masalah #4: 'save(List<T>)' in 'com.interpretzz.approval.dao.AbstractHibernateDao' clashes with 'save(List<T>)' in 'com.interpretzz.approval.dao.GenericHibernateDao'; attempting to assign weaker access privileges ('package-private'); was 'public'.

Maksudnya function dalam AbstractHibernateDao (kelas abstrak) mempunyai access privileges yang berbeza dengan GenericHibernateDao (interface).
Jadi kita kena jadikan access privileges AbstractHibernateDao sebagai public.

Ini adalah kerana fungsi dalam interface pada umumnya adalah public.


20200104