title: Memory Leak Springboot
body: <p>I have an application that seems to be using too much memory. I have been trying to find the source for a while. But still no luck.</p>
  
  <p>I have read several articles pointing at JPA as the culprit for some of the memory issues with Spring Boot. I only have a single repository so I cannot imagine it be the issue.</p>
  
  <pre><code>@Repository
  public interface  WordRepository extends JpaRepository&lt;Word, Long&gt; {
  
      @Query("SELECT w FROM Word w WHERE w.value IN (:words)")
      List&lt;Word&gt; findAllIn(@Param("words") List&lt;String&gt; words);
  
      Word findFirstByValue(String value);
  
      @Transactional
      Long removeByValue(String value);
  
      Page&lt;Word&gt; findAllByCategory(Pageable pageable, String category);
  }
  </code></pre>
  
  <p>I have another class which is a helper for dropping the table. I cannot do that with JPA (that I know of) so I am getting a hold of the persistance object and using it to truncate the table.</p>
  
  <pre><code>@Service
  public class WordRepositoryHelper {
  
      @PersistenceContext(unitName = "default")
      private EntityManager entityManager;
  
      @Transactional
      public int truncateWordTable() {
          final String sql = "truncate table word";
          entityManager.createNativeQuery(sql).executeUpdate();
          return 1;
      }
  }
  </code></pre>
  
  <p>I am using them as in here.</p>
  
  <pre><code>@Service
  @SuppressWarnings("deprecation")
  public class CSVResourceService implements ResourceService {
  
      @Autowired
      private WordRepository wordRepository;
  
      @Autowired
      private WordRepositoryHelper wordRepositoryHelper;
  
      private static final String HEADER_ID = "id";
      private static final String HEADER_VALUE = "value";
      private static final String HEADER_CATEGORY = "category";
  
      @Override
      public Boolean save(MultipartFile file, Boolean replace) throws Exception {
  
          // some other code
  
          if (replace) {
              wordRepositoryHelper.truncateWordTable();
          }
  
          //some other code
      }
  }
  </code></pre>
  
  <p>Any guidance on the issue or suggestion. </p>