If you are using JPA, it is highly recommended that you keep an eye out for the generated SQL statements so that you can avoid any poorly generated queries. In JBoss AS 7, take these steps to view the SQL statements.
First, in your persistence.xml, add the showSql parameter.
<persistence ...> <persistence-unit name="..."> ... <properties> <property name="showSql" value="true"/> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> </properties> </persistence-unit> </persistence>
Next, open the server’s configuration file. For example, for standalone server, it will be JBOSS/standalone/configuration/standalone.xml. Locate the start of the logging subsystem by looking for this line:
<subsystem xmlns="urn:jboss:domain:logging:1.1">
Somewhere below that add:
<logger category="org.hibernate.SQL"> <level name="TRACE"/> </logger>
Save the file and restart the server. Now, in Eclipse Console or in server’s server.log file, you will see all SQL statements executed by JPA. It will look something like this.
09:49:24,227 DEBUG [org.hibernate.SQL] (http-localhost-127.0.0.1-8080-1) select product0_.id as id3_0_, product0_.description as descript2_3_0_, product0_.imageLink as imageLink3_0_, product0_.name as name3_0_, product0_.price as price3_0_, product0_.sku as sku3_0_ from Product product0_ where product0_.id=?