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

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

Open
XxTaro opened this issue Mar 21, 2023 · 2 comments

Comments

@XxTaro
Copy link

XxTaro commented Mar 21, 2023

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?

@j256
Copy link
Owner

j256 commented Jul 7, 2023

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?

@rahulstech
Copy link

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.

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