ormlite-core icon indicating copy to clipboard operation
ormlite-core copied to clipboard

A bigger query causing "java.lang.StackOverflowError: stack size 8192KB" exception

Open XxTaro opened this issue 2 years ago • 2 comments

The following code, when arrive at line "queryBuilder.prepare();" it's broking the application throwing "java.lang.StackOverflowError: stack size 8192KB", and if I remove the between operator in "queryBuilder", the code runs fine

LogDao logDao = new LogDao(this.getConnectionSource());
DetailsDao detailsDao = new DetailsDao(this.getConnectionSource());

QueryBuilder<LogEntity, Integer> queryBuilder;
QueryBuilder<DetailsEntity, Integer> detailsQueryBuilder;

//Logs without details
detailsQueryBuilder = detailsDao.queryBuilder();
detailsQueryBuilder
          .where()
          .notIn("id", detailsQueryBuilder.selectColumns("log_id"));

queryBuilder = logDao.queryBuilder();
queryBuilder
          .join(detailsQueryBuilder)
          .where()
          .between("timestamp", initDate, finalDate); //initDate and finalDate is passed in function param
PreparedQuery preparedQuery = queryBuilder.prepare();

in console show a lot of E/AndroidRuntime exception in sequence:

E/AndroidRuntime:     at com.j256.ormlite.stmt.query.InSubQuery.appendSql(InSubQuery.java:17)
        at com.j256.ormlite.stmt.Where.appendSql(Where.java:609)
        at com.j256.ormlite.stmt.StatementBuilder.appendWhereStatement(StatementBuilder.java:163)
        at com.j256.ormlite.stmt.QueryBuilder.appendWhereStatement(QueryBuilder.java:530)
        at com.j256.ormlite.stmt.StatementBuilder.appendStatementString(StatementBuilder.java:145)
        at com.j256.ormlite.stmt.QueryBuilder$InternalQueryBuilderWrapper.appendStatementString(QueryBuilder.java:926)
        at com.j256.ormlite.stmt.query.InSubQuery.appendValue(InSubQuery.java:42)
        at com.j256.ormlite.stmt.query.BaseComparison.appendSql(BaseComparison.java:49)
        at com.j256.ormlite.stmt.query.InSubQuery.appendSql(InSubQuery.java:17)
        at com.j256.ormlite.stmt.Where.appendSql(Where.java:609)
        at com.j256.ormlite.stmt.StatementBuilder.appendWhereStatement(StatementBuilder.java:163)
        at com.j256.ormlite.stmt.QueryBuilder.appendWhereStatement(QueryBuilder.java:530)
        at com.j256.ormlite.stmt.StatementBuilder.appendStatementString(StatementBuilder.java:145)
        at com.j256.ormlite.stmt.QueryBuilder$InternalQueryBuilderWrapper.appendStatementString(QueryBuilder.java:926)
        at com.j256.ormlite.stmt.query.InSubQuery.appendValue(InSubQuery.java:42)
        at com.j256.ormlite.stmt.query.BaseComparison.appendSql(BaseComparison.java:49)
        at com.j256.ormlite.stmt.query.InSubQuery.appendSql(InSubQuery.java:17)
        at com.j256.ormlite.stmt.Where.appendSql(Where.java:609)
        at com.j256.ormlite.stmt.StatementBuilder.appendWhereStatement(StatementBuilder.java:163)
        at com.j256.ormlite.stmt.QueryBuilder.appendWhereStatement(QueryBuilder.java:530)
        at com.j256.ormlite.stmt.StatementBuilder.appendStatementString(StatementBuilder.java:145)
        at com.j256.ormlite.stmt.QueryBuilder$InternalQueryBuilderWrapper.appendStatementString(QueryBuilder.java:926)
        at com.j256.ormlite.stmt.query.InSubQuery.appendValue(InSubQuery.java:42)
        at com.j256.ormlite.stmt.query.BaseComparison.appendSql(BaseComparison.java:49)
        at com.j256.ormlite.stmt.query.InSubQuery.appendSql(InSubQuery.java:17)
        at com.j256.ormlite.stmt.Where.appendSql(Where.java:609)
        at com.j256.ormlite.stmt.StatementBuilder.appendWhereStatement(StatementBuilder.java:163)
        at com.j256.ormlite.stmt.QueryBuilder.appendWhereStatement(QueryBuilder.java:530)
        at com.j256.ormlite.stmt.StatementBuilder.appendStatementString(StatementBuilder.java:145)
        at com.j256.ormlite.stmt.QueryBuilder$InternalQueryBuilderWrapper.appendStatementString(QueryBuilder.java:926)
        at com.j256.ormlite.stmt.query.InSubQuery.appendValue(InSubQuery.java:42)
        at com.j256.ormlite.stmt.query.BaseComparison.appendSql(BaseComparison.java:49)
        at com.j256.ormlite.stmt.query.InSubQuery.appendSql(InSubQuery.java:17)
        at com.j256.ormlite.stmt.Where.appendSql(Where.java:609)
        at com.j256.ormlite.stmt.StatementBuilder.appendWhereStatement(StatementBuilder.java:163)
        at com.j256.ormlite.stmt.QueryBuilder.appendWhereStatement(QueryBuilder.java:530)
        at com.j256.ormlite.stmt.StatementBuilder.appendStatementString(StatementBuilder.java:145)
        at com.j256.ormlite.stmt.QueryBuilder$InternalQueryBuilderWrapper.appendStatementString(QueryBuilder.java:926)
        at com.j256.ormlite.stmt.query.InSubQuery.appendValue(InSubQuery.java:42)
        at com.j256.ormlite.stmt.query.BaseComparison.appendSql(BaseComparison.java:49)
        at com.j256.ormlite.stmt.query.InSubQuery.appendSql(InSubQuery.java:17)
        at com.j256.ormlite.stmt.Where.appendSql(Where.java:609)
        at com.j256.ormlite.stmt.StatementBuilder.appendWhereStatement(StatementBuilder.java:163)
        at com.j256.ormlite.stmt.QueryBuilder.appendWhereStatement(QueryBuilder.java:530)
        at com.j256.ormlite.stmt.StatementBuilder.appendStatementString(StatementBuilder.java:145)
        at com.j256.ormlite.stmt.QueryBuilder$InternalQueryBuilderWrapper.appendStatementString(QueryBuilder.java:926)
        at com.j256.ormlite.stmt.query.InSubQuery.appendValue(InSubQuery.java:42)
        at com.j256.ormlite.stmt.query.BaseComparison.appendSql(BaseComparison.java:49)

I'm trying to understand this problem, but until the moment i do not realize what could be. Can help me?

XxTaro avatar Mar 21 '23 18:03 XxTaro

I don't think you want to do this:

detailsQueryBuilder
          .where()
          .notIn("id", detailsQueryBuilder.selectColumns("log_id"));

The detailsQueryBuilder.selectColumns(...) returns the detailsQueryBuilder to do chaining so this in effect makes the query not-in itself which goes recursive.

I'm not immediately sure what the notIn(...) second argument should be. If you are trying to get all of the log-ids out of the details then you will need another query that returns all unique log-ids maybe?

j256 avatar Jul 07 '23 19:07 j256

detailsQueryBuilder
          .where()
          .notIn("id", detailsQueryBuilder.selectColumns("log_id"));

the immediate change you can do:

detailsQueryBuilder
          .where()
          .notIn("id", detailsDao.queryBuilder().selectColumns("log_id")); // this will return all the log_id in the details table

but this will return empty result becuse the where statement filter outs all the log_id in the table. give the table relationship of LogEntity and DetailEntity. also provide the exact sql select statement you want to execute. thus the exact code can be provided.

rahulstech avatar Jul 07 '24 15:07 rahulstech