Posts

Showing posts with the label Hibernate

Spring data JPA Hibernate mapping dynamic query to List(Map) instead List POJO

Image
 Hi every one, This way i'll show you how to mapping dynamic query on hibernate to list<map> for dynamic result instead create new pojo/ dto class✋ - You can be use only hibernate or spring data jpa(including hibernate on compile dependencies) 👌 Importing framework Build tool: Grandle, spring boot 3.x.x a. Dependencies : implementation 'org.springframework.boot:spring-boot-starter-data-jpa'   b. Compile dependencies on spring data jpa: c. Version: id 'org.springframework.boot' version '3.0.2'    Implementing 1. Create a generic repository custom public interface GenericRepoCustom { long counting ( String sql ) ; List findStrategy ( String sql , Class clazz ) ; }   2.  Autowire GenericRepoCustom on service   3. Call it and passing class type List < Map > orders = genericRepo .findStrategy( strSQL , Map . class );   strSQL : work well when get one or get list 4. Create function mapping if clazz is Map.class import jakarta.persistence.E