{"action":"created","issue":{"url":"https://api.github.com/repos/querydsl/querydsl/issues/1581","labels_url":"https://api.github.com/repos/querydsl/querydsl/issues/1581/labels{/name}","comments_url":"https://api.github.com/repos/querydsl/querydsl/issues/1581/comments","events_url":"https://api.github.com/repos/querydsl/querydsl/issues/1581/events","html_url":"https://github.com/querydsl/querydsl/issues/1581","id":108154599,"number":1581,"title":"Using SQLQueryFactory's query(), subqueries are assigned connections and never close them","user":{"login":"robertandrewbain","id":3799239,"avatar_url":"https://avatars.githubusercontent.com/u/3799239?v=3","gravatar_id":"","url":"https://api.github.com/users/robertandrewbain","html_url":"https://github.com/robertandrewbain","followers_url":"https://api.github.com/users/robertandrewbain/followers","following_url":"https://api.github.com/users/robertandrewbain/following{/other_user}","gists_url":"https://api.github.com/users/robertandrewbain/gists{/gist_id}","starred_url":"https://api.github.com/users/robertandrewbain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertandrewbain/subscriptions","organizations_url":"https://api.github.com/users/robertandrewbain/orgs","repos_url":"https://api.github.com/users/robertandrewbain/repos","events_url":"https://api.github.com/users/robertandrewbain/events{/privacy}","received_events_url":"https://api.github.com/users/robertandrewbain/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-09-24T15:28:35Z","updated_at":"2015-09-29T20:54:42Z","closed_at":null,"body":"When using `SQLQueryFactory`'s `query()` method to create a subquery, each subquery is assigned a new connection, as the connection object is assigned when `query()` is called. Furthmore, using a `SQLCloseListener` does not close subqueries, I presume because a terminator E.G. `.list()` etc. has not been called on it. This caused my system test environment to grind to a halt when the querydsl 4 upgrade was pushed up.\r\n\r\nAfter realising what was happening, I discovered `SQLExpressions.select` which will \"Create a new detached SQLQuery instance with the given projection\". After some debugging I realised this creates a `SQLQuery` instance with a null connection - so far so good. I assume detached means not attached to a connection. If so `SQLQueryFactory`'s  `public <T> SQLQuery<T> selectFrom(RelationalPath<T> expr)` method's documentation is wrong.\r\n\r\nSo for me, the issue here is that if you're using a `SQLQueryFactory`, creating a subquery using `query()` looks sensible and will work, but will swallow a connection. It feels like a connection should not be getting assigned on calling `query()`, surely the connection is not required until calling a terminator?\r\n\r\nSecondly, `SQLCloseListener ` should close these connections.\r\n"},"comment":{"url":"https://api.github.com/repos/querydsl/querydsl/issues/comments/144188626","html_url":"https://github.com/querydsl/querydsl/issues/1581#issuecomment-144188626","issue_url":"https://api.github.com/repos/querydsl/querydsl/issues/1581","id":144188626,"user":{"login":"timowest","id":574167,"avatar_url":"https://avatars.githubusercontent.com/u/574167?v=3","gravatar_id":"","url":"https://api.github.com/users/timowest","html_url":"https://github.com/timowest","followers_url":"https://api.github.com/users/timowest/followers","following_url":"https://api.github.com/users/timowest/following{/other_user}","gists_url":"https://api.github.com/users/timowest/gists{/gist_id}","starred_url":"https://api.github.com/users/timowest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timowest/subscriptions","organizations_url":"https://api.github.com/users/timowest/orgs","repos_url":"https://api.github.com/users/timowest/repos","events_url":"https://api.github.com/users/timowest/events{/privacy}","received_events_url":"https://api.github.com/users/timowest/received_events","type":"User","site_admin":false},"created_at":"2015-09-29T20:54:42Z","updated_at":"2015-09-29T20:54:42Z","body":"> Why not just grab one when executing the SQL statement?\r\n\r\nThat was suggested above, but we still need to provide the old constructors for backwards compatibility. I think the `Provider<Connection>` approach could work."}}