Alternative to JPA Implementation

3

I'm using JPA in a project, with Hibernate implementation, I still use Java 7.

And PermGen is constantly running out of space. I know it's because of Hibernate, as I'm new to this Java technology. Does anyone know to indicate some less heavy implementation for JPA. I was using EclipseLink it was worse because neither deploy I did.

I did not want to increase PermGen, I wanted a solution and not a palliative.

In Java 8, I do not have this annoyance because it does not exist anymore, it has been replaced by Metaspace, even though the application grows too.

Any tips?

    
asked by anonymous 10.03.2014 / 02:49

2 answers

1

Staff at Batoo claims that it is a lightweight and fast implementation. The code is open and you can test the Benchmark at link .

This post the author says that Batto is 15 times faster than Hibernate.

I think it's worth a try.

Another option is to abandon JPA and use something simpler like the Data Access Object (DAO) Pattern and in this case take a look at this implementation ORMLite . Sometimes your data model is complex enough and a DAO Pattern does not solve.

    
11.03.2014 / 13:26
3

I'd say your problem is more related to how you use JPA than JPA as a problem.

EclipseLink, Hibernate, OpenJPA or Batoo will continue to cause problems. With Java8 you will burst the memory in the same way, the difference is the type of error that will appear.

This error appears with JPA when you bring too much data into memory. This error would also appear with JDBC very easily .

Some solutions to this problem are:

  • Paged Search - Instead of simply fetching 15,000 results from the database, just bring what will be displayed to the user
  • Avoid relationships annotated with @EAGER. When annotating relationships with @EAGER you will be bringing unnecessary information and with that will flood memory unnecessarily
  • Make specific queries with JPQL. If you need to bring relationship data, create a JPQL for this, for example: select c from Cachorro c join on c.pessoas p where c.id = 33 Note that with this I limit the data that will be brought.
  • Bring your objects as detached. You optimize the use of JPA if it is just a 'read only' query for information. With EJB use transaction NOT_SUPPORTED, with Spring @Transactional (readOnly = true) and if it is manual transaction do not entityManager.getTransaction().begin() .
  • Now, in case you want to quit JPA you could take a look at MyBatis ( link ) or QueryDSL ( link )

        
    10.03.2014 / 03:30