Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Query(value=[SQL query with several joins],nativeQuery=true)
- List<Media> mySQLQuery()
- interface MyRepo implements<Media, Long>....
- myRepo.findAll() will return a List of Media objects.
- public interface CustomQuery {
- public List<Integer>myCustomQuery(int id)
- }
- @Component
- public class MediaRepositoryImpl implements CustomQuery {
- @PersistenceContext
- EntityManager manager;
- public List<Integer>myCustomQuery(int id){
- Query q = manager.createNativeQuery(SQL_QUERY_GOES_HERE);
- List<Integer> ids = new ArratList<Integer>();
- @SuppressWarnings("unchecked")
- List<Integer> result = q.getResultList();
- for(Integer o : result){
- //process the results and add them to the list
- }
- return list;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement