Play Framework 2.0 and Ebean SQL logging

后端 未结 3 1198
轮回少年
轮回少年 2020-12-01 17:58

I want to examine what SQL statements are generated by Ebean to find out why certain exceptions (related to SQL syntax) are occurring in my Play 2.0 application. Is

相关标签:
3条回答
  • 2020-12-01 18:33

    Also you can get SQL on the spot by using method getGeneratedSQL. Code sample below

            Query<PreventionActivity> where = find.where(
                and(
                        and(
                        ge("Age_FROM", age)
                        , or(le("Age_TO", age), eq("Age_TO", 0))
                        )
                        , or(eq("Gender_CD", genderCd), eq("Gender_CD", "*"))
                )
        );
    
        List<PreventionActivity> list = where.findList();
        Logger.info("sql ");
        Logger.info(where.getGeneratedSql());
    
    0 讨论(0)
  • 2020-12-01 18:40

    You can enable SQL logging by using the following statement

    Ebean.getServer(null).getAdminLogging().setDebugGeneratedSql(true);
    

    Use this command in the onRequest interceptor for example

    In a next release, you will certainly be able to configure this in the file ebean.properties.

    // Tips : use Play.isDev() to log only in dev mode
    
    0 讨论(0)
  • 2020-12-01 18:41

    Sorry to be late to the party, but I use this in development:

    db.default.logStatements=true
    
    logger.com.jolbox=DEBUG
    

    Add those two lines to the application.conf and you are good to go.

    It outputs all the sql statements. Hope it helps.

    0 讨论(0)
提交回复
热议问题