Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for JPAApi, problem with JPAApi.em() #4862

Closed
johdah opened this issue Jul 16, 2015 · 4 comments
Closed

Documentation for JPAApi, problem with JPAApi.em() #4862

johdah opened this issue Jul 16, 2015 · 4 comments

Comments

@johdah
Copy link

johdah commented Jul 16, 2015

I think we need documentation for how to use JPAApi. I think I have almost solved it now, my implementation looks like this:

UserDAO

public class UserDAO extends AbstractDAO<User, User_> {
    JedisPool jedisPool;

    @Inject
    public UserDAO(final JPAApi jpaApi, JedisPool jedisPool) {
        super(jpaApi, User.class, User_.class);
        this.jedisPool = jedisPool;
    }

    ...
}

AbstractDAO

public abstract class AbstractDAO<T extends AbstractModel, M extends AbstractModel_> {
    protected final Class<T> classType;
//    protected final M metaclass;
    protected final EntityManager em;
    protected final CriteriaBuilder cb;

    public AbstractDAO(final JPAApi jpaApi, Class<T> classType, Class<M> metaType) {
        String jpaDefault = Play.application().configuration().getString("jpa.default");
        this.em = jpaApi.em(jpaDefault != null ? jpaDefault : "defaultPersistenceUnit");
        this.cb = em.getCriteriaBuilder();
        this.classType = classType;
//        try {
//            this.metaclass = metaType.newInstance();
//        } catch(Exception ex) {
//            throw new RuntimeException(ex);
//        }
    }

    ...
}

I get a Null Pointer Exception on em.getCriteriaBuilder so I guess it wasn't correct to pass the name of the persistence unit to jpaApi.em() so what should be given as the parameter there?

@Kdoherty11
Copy link

@johdah I'm having the same issue. Did you ever figure out a solution?

@johdah
Copy link
Author

johdah commented Jul 29, 2015

@Kdoherty11 I solved that problem by loading the DAO this way:

UserDAO userDAO = play.Play.application().injector().instanceOf(UserDAO.class);

But now I get this error everywhere. I have no idea what has changed since 2.3.x that causes this and it's hard to find somebody that does. I have this question for that, does it work for you with my code above?

https://groups.google.com/forum/#!topic/play-framework/i4flTpToCug

2015-07-29 15:42:16,822 - [warn] o.h.e.j.s.SqlExceptionHelper - SQL Error: 0, SQLState: null
2015-07-29 15:42:16,822 - [error] o.h.e.j.s.SqlExceptionHelper - Timeout after 120000ms of waiting for a connection.
2015-07-29 15:42:16,854 - [error] application - 

! @6n1ehgfdj - Internal server error, for (GET) [/index] ->

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[QueryTimeoutException: Could not open connection]]
    at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:265) ~[play_2.11-2.4.2.jar:2.4.2]
    at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:191) ~[play_2.11-2.4.2.jar:2.4.2]
    at play.api.GlobalSettings$class.onError(GlobalSettings.scala:179) [play_2.11-2.4.2.jar:2.4.2]
    at play.api.DefaultGlobal$.onError(GlobalSettings.scala:212) [play_2.11-2.4.2.jar:2.4.2]
    at play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorHandler.scala:94) [play_2.11-2.4.2.jar:2.4.2]
Caused by: javax.persistence.QueryTimeoutException: Could not open connection
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1725) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]
    at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:458) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]
    at org.hibernate.jpa.criteria.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:67) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]
    at dao.AbstractDAO.findMany(AbstractDAO.java:92) ~[classes/:na]
Caused by: org.hibernate.QueryTimeoutException: Could not open connection
    at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:83) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
    at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:235) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
Caused by: java.sql.SQLTimeoutException: Timeout after 120000ms of waiting for a connection.
    at com.zaxxer.hikari.pool.BaseHikariPool.getConnection(BaseHikariPool.java:227) ~[HikariCP-2.3.7.jar:na]
    at com.zaxxer.hikari.pool.BaseHikariPool.getConnection(BaseHikariPool.java:182) ~[HikariCP-2.3.7.jar:na]
    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:93) ~[HikariCP-2.3.7.jar:na]
    at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
    at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:380) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]

@johdah
Copy link
Author

johdah commented Jul 30, 2015

@Kdoherty11 If you get that error also it's caused by the fact that no connections are closed so HikariCP is filling upp the connection pool that is 10 by default. The leak detection is triggered on every connection.

@marcospereira
Copy link
Member

@johdah and @Kdoherty11 I'm closing this issue in favor of #4890.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants