Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. @Query(value=[SQL query with several joins],nativeQuery=true)
  2. List<Media> mySQLQuery()
  3.  
  4. interface MyRepo implements<Media, Long>....
  5.  
  6. myRepo.findAll() will return a List of Media objects.
  7.  
  8. public interface CustomQuery {
  9. public List<Integer>myCustomQuery(int id)
  10. }
  11.  
  12. @Component
  13. public class MediaRepositoryImpl implements CustomQuery {
  14. @PersistenceContext
  15. EntityManager manager;
  16.  
  17. public List<Integer>myCustomQuery(int id){
  18. Query q = manager.createNativeQuery(SQL_QUERY_GOES_HERE);
  19. List<Integer> ids = new ArratList<Integer>();
  20.  
  21. @SuppressWarnings("unchecked")
  22. List<Integer> result = q.getResultList();
  23. for(Integer o : result){
  24. //process the results and add them to the list
  25. }
  26. return list;
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement