日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Hibernate中启用日志

發布時間:2025/3/20 编程问答 13 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Hibernate中启用日志 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Problem

How do you determine what SQL query is being executed by Hibernate? How can you see the Hibernate’ internal workings? How do you enable logging to troubleshoot complex issues related to Hibernate?

Solution

You have to enable Hibernate logging in the Hibernate configuration. Hibernate uses Simple Logging Facade for Java (SLF4J) to log various system events. SLF4J, which is distributed as a free software license, abstracts the actual logging framework that an application uses. SLF4J can direct your logging output to several logging frameworks:

  • NOP: Null logger implementation
  • Simple: A logging antiframework that is very simple to use and attempts to solve every logging problem in one package
  • Log4j version 1.2: A widely used open–source logging framework
  • JDK 1.4 logging: A logging API provided by Java
  • JCL: An open-source Commons logging framework that provides an interface with thin wrapper implementations for other logging tools
  • Logback: A serializable logger that logs after its deserialization, depending on the chosen binding

To set up logging, you need the slf4j-api.jar file in your classpath, together with the JAR file for your preferred binding: slf4j-log4j12.jar in the case of log4j. You can also enable a property called showsql to see the exact query being executed. You can configure a logging layer such as Apache log4j to enable Hibernate class- or package-level logging. And you can use the Statistics interface provided by Hibernate to obtain detailed information.

How It Works

You have to configure the Hibernate show_sql property to enable logging.

Inspecting the SQL Statements Issued by Hibernate

Hibernate generates SQL statements that enable you to access the database behind the scene. You can set the show_sql property to true in the hibernate.cfg.xml XML configuration file to print the SQL statements to stdout:

<property name="show_sql">true</property>

Enabling Live Statistics

You can enable live statistics by setting the hibernate.generate_statistics property in the configuration file:

<property name="hibernate.generate_statistics">true</property>

You can also access statistics programmatically by using the Statistics interfaces. Hibernate provides SessionStatistics and Statistics interfaces in the org.hibernate.stat package. The following code shows the use of some utility methods:

1 SessionFactory sessionFactory = SessionManager.getSessionFactory(); 2 session = sessionFactory.openSession(); 3 SessionStatistics sessionStats = session.getStatistics(); 4 Statistics stats = sessionFactory.getStatistics(); 5 tx = session.beginTransaction(); 6 Publisher publisher = new Publisher(); 7 publisher.setCode("apress"); 8 publisher.setName("Apress"); 9 publisher.setAddress("233 Spring Street, New York, NY 10013"); 10 session.persist(publisher); 11 tx.commit(); 12 logger.info("getEntityCount- " + sessionStats.getEntityCount()); 13 logger.info("openCount- " + stats.getSessionOpenCount()); 14 logger.info("getEntityInsertCount- " + stats.getEntityInsertCount()); 15 stats.logSummary(); 16 session.close();

?

The output of this code sample is shown here (the complete log is given for clarity):

HCANN000001: Hibernate Commons Annotations {4.0.4.Final} HHH000412: Hibernate Core {4.3.5.Final} HHH000206: hibernate.properties not found HHH000021: Bytecode provider name : javassist HHH000043: Configuring from resource: /hibernate.cfg.xml HHH000040: Configuration resource: /hibernate.cfg.xml HHH000221: Reading mappings from resource: com/apress/hibernaterecipes/chapter1/model/Book.hbm.xml HHH000221: Reading mappings from resource: com/apress/hibernaterecipes/chapter1/model/Publisher.hbm.xml HHH000041: Configured SessionFactory: null HHH000402: Using Hibernate built-in connection pool (not for production use!) HHH000401: using driver [org.hsqldb.jdbcDriver] at URL [jdbc:hsqldb:file:./chapter1;write_delay=false] HHH000046: Connection properties: {} HHH000006: Autocommit mode: false HHH000115: Hibernate connection pool size: 20 (min=1) HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect HHH000399: Using default transaction strategy (direct JDBC transactions) HHH000397: Using ASTQueryTranslatorFactory HHH000227: Running hbm2ddl schema export HHH000230: Schema export complete Session Metrics { ???   14000 nanoseconds spent acquiring 1 JDBC connections; ??? 0 nanoseconds spent releasing 0 JDBC connections; ??? 2445000 nanoseconds spent preparing 2 JDBC statements; ??? 1636000 nanoseconds spent executing 2 JDBC statements; ??? 0 nanoseconds spent executing 0 JDBC batches; ??? 0 nanoseconds spent performing 0 L2C puts; ??? 0 nanoseconds spent performing 0 L2C hits; ??? 0 nanoseconds spent performing 0 L2C misses; ??? 0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections); ??? 59000 nanoseconds spent executing 2 partial-flushes (flushing a total of 0 entities and 0 collections) } getEntityCount- 1 openCount- 2 getEntityInsertCount- 1 HHH000161: Logging statistics.... HHH000251: Start time: 1408349026472 HHH000242: Sessions opened: 2 HHH000241: Sessions closed: 1 HHH000266: Transactions: 2 HHH000258: Successful transactions: 2 HHH000187: Optimistic lock failures: 0 HHH000105: Flushes: 1 HHH000048: Connections obtained: 2 HHH000253: Statements prepared: 3 HHH000252: Statements closed: 0 HHH000239: Second level cache puts: 0 HHH000237: Second level cache hits: 0 HHH000238: Second level cache misses: 0 HHH000079: Entities loaded: 0 HHH000080: Entities updated: 0 HHH000078: Entities inserted: 1 HHH000076: Entities deleted: 0 HHH000077: Entities fetched (minimize this): 0 HHH000033: Collections loaded: 0 HHH000036: Collections updated: 0 HHH000035: Collections removed: 0 HHH000034: Collections recreated: 0 HHH000032: Collections fetched (minimize this): 0 HHH000438: NaturalId cache puts: 0 HHH000439: NaturalId cache hits: 0 HHH000440: NaturalId cache misses: 0 HHH000441: Max NaturalId query time: 0ms HHH000442: NaturalId queries executed to database: 0 HHH000210: Queries executed to database: 0 HHH000215: Query cache puts: 0 HHH000433: update timestamps cache puts: 0 HHH000434: update timestamps cache hits: 0 HHH000435: update timestamps cache misses: 0 HHH000213: Query cache hits: 0 HHH000214: Query cache misses: 0 HHH000173: Max query time: 0ms Session Metrics { ??? 5000 nanoseconds spent acquiring 1 JDBC connections; ??? 0 nanoseconds spent releasing 0 JDBC connections; ??? 262000 nanoseconds spent preparing 1 JDBC statements; ??? 828000 nanoseconds spent executing 1 JDBC statements; ??? 0 nanoseconds spent executing 0 JDBC batches; ??? 0 nanoseconds spent performing 0 L2C puts; ??? 0 nanoseconds spent performing 0 L2C hits; ??? 0 nanoseconds spent performing 0 L2C misses; ??? 8131000 nanoseconds spent executing 1 flushes (flushing a total of 1 entities and 0 collections); ??? 0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0 collections) }

轉載于:https://www.cnblogs.com/IcanFixIt/p/4371128.html

總結

以上是生活随笔為你收集整理的Hibernate中启用日志的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产噜噜噜噜噜久久久久久久久 | 日韩播放 | 亚洲第七页 | 蜜桃视频欧美 | 可以免费看的av毛片 | 国内久久久 | 穿扒开跪着折磨屁股视频 | 91精品99| 最新中文字幕在线播放 | 国产欧美高清 | ,国产精品国产三级国产 | 精品不卡视频 | 免费在线观看成年人视频 | 国产色诱视频 | 神马午夜嘿嘿 | 久久久久久无码精品大片 | 亚洲精品视频免费看 | 亚洲人成无码www久久久 | 俄罗斯一级片 | 欧美怡红院视频一区二区三区 | 九九九视频在线观看 | 久久久一区二区三区四区 | 国产性生活网站 | 麻豆综合 | 午夜免费在线 | 熟女丰满老熟女熟妇 | 久久久999| 四虎免看黄 | 白嫩少妇激情无码 | 成人免费在线电影 | 麻豆成人在线 | 波多野结衣av中文字幕 | 久久国产精品网站 | 亚洲一区 中文字幕 | 欧美性猛交乱大交xxxx | 老司机午夜免费视频 | 亚洲第一大综合区 | 涩涩视频免费在线观看 | 奇米第四色在线 | 青娱乐青青草 | 99热在线这里只有精品 | 国产成人在线视频播放 | 30一40一50女人毛片 | 鲁一鲁一鲁一鲁一av | 在线观看国产一区二区三区 | 国产又色又爽又黄 | 国产精品久久777777换脸 | 欧美三级一区二区三区 | 青青草视频免费观看 | 日韩在线色 | 国产一区二区视频免费在线观看 | 特种兵之深入敌后高清全集免费观看 | 日韩精品视频免费 | 黄频在线观看 | 波多野结衣在线一区二区 | 极品福利视频 | 国产精品久久久久久久久晋中 | 91成人在线播放 | 大吊一区二区三区 | 岛国中文字幕 | 不卡av影院| porn国产| 日韩aa | 国产美女免费视频 | 香蕉一区二区三区四区 | 亚洲av综合色区无码一二三区 | 天天草夜夜草 | 在线成人日韩 | 在线观看网站黄 | 少妇一级淫片免费 | www国产一区 | 人妻丰满熟妇av无码久久洗澡 | 免费视频日韩 | 激情五月综合网 | 91噜噜噜| 亚洲天堂一区在线观看 | 久热伊人 | 严厉高冷老师动漫播放 | 国产无遮挡又黄又爽又色视频 | 2017狠狠干| 美女精品在线观看 | 久久538| 四川话毛片少妇免费看 | 91免费版在线看 | 日韩精品在线观看一区二区 | 在线看国产精品 | 91伊人| 成人国产精品 | 日韩黄色片 | 男生舔女生胸 | 黄色免费91| 一二三区在线播放 | a级在线播放 | 91视频这里只有精品 | 午夜激情亚洲 | 对白刺激国产子与伦 | 日本va欧美va国产激情 | 欧美午夜在线视频 | 久久久艹|