Category Archives: Database

Hibernate Fetch Lazy Child Entities with HQL and Native SQL

In one-to-many or many-to-many relationship, we often configure Hibernate to lazily fetch the children collection for performance reasons by reducing the database join operation and the amount of the data been pulled and transmitted from database to application. The application, … Continue reading

Posted in Database, Java | Tagged , , , , , , , , | Leave a comment

Cleanup Stale Hibernate Session in Tomcat

Problem: When Hibernate is configured to use thread based session management, a thread may get stuck (unable to unbind) with a closed session under certain condition, therefore all subsequent incoming HTTP calls assigned to such a thread would fail until … Continue reading

Posted in Database, Java | Tagged , , , , | Leave a comment

Use ScriptDom to Parse SQL Script

Microsoft provides a ScriptDom library that you can use to parse T-SQL script. It can be used with any CLR languages to quickly write your own SQL parser. This blog uses c# in its examples. Installation First, you need to … Continue reading

Posted in Database, Uncategorized | Tagged , , | Leave a comment

Show Query Statistics in SSMS

You can turn on the statistics before executing your SQL statement. In SSMS, you can do This output the time and io statistics to the Messages tab. And you can correlate the numbers to the Execution Plan output the check … Continue reading

Posted in Database, Tool and Debug | Tagged , , | Leave a comment

How to Avoid Accidentally Update All Rows

Here are just some thoughts on preventing this problem: Before sql submitted to be executed Peer Code review: Although it may be not necessary to fully review the details, a quick review ┬ácan at least catch some blunt errors such … Continue reading

Posted in Best Software Practices, Database | Tagged | Leave a comment

Trace Deadlocks with SQL Server Profiler

Deadlocks can happen at anytime and processes compete for locks, threads, memory or other shareable resources. SQL server periodically detected deadlocks and kill one of the blocking one as victim. In many cases, we want to know the processes involved … Continue reading

Posted in Database, Tool and Debug | Tagged , , | Leave a comment

Open H2 UI When Debugging in Eclipse

This time it is about debugging the H2 embedded database, which is very similar to procedure used with the HSQLDB I posted earlier. Assuming that the hibernate.connection.url is set to jdbc:h2:mem:myDb, you can following similar steps as in my previous … Continue reading

Posted in Database, Java, Tool and Debug | Tagged , , , , | Leave a comment