Hibernate
Repository creating tables automatically
by Frank Kim on Aug.01, 2008, under Hibernate, Repository
Recently we noticed while running some ATG unit tests that tables were being created by the ATG repository if they had not already been created by our SQL scripts. This was a functionality that I was unaware of but apparently it is not unique, Hibernate does this too. I could not find any documentation about this nor could I determine how to turn it off.
The ATG repository creates these tables using the repository definition and the defaults for column width and data type. It does not seem to warn that it is creating these tables.
HibernateException: Found two representations of same collection
by Frank Kim on Jan.26, 2007, under Hibernate
Sometimes you might stumble upon this confusing exception.
org.hibernate.HibernateException: Found two representations of same collection: com.betweengo.Foos
This could have happened because after clearing a Hibernate session (session.clear()) you updated a property that contains a collection. I found just making sure to clear the session once seemed to fix the problem but that may not be a suitable solution in more complex situations.
More information about this problem can be found at http://forum.hibernate.org/viewtopic.php?p=2231400.
Catching Oracle exceptions
by Frank Kim on Jan.26, 2007, under Hibernate, Oracle
Oracle SQL queries can throw exceptions. For example in this query f there is no data then Oracle will throw a NO_DATA_FOUND exception.
SELECT status_date INTO v_status_date FROM member WHERE member_id = p_member_id_in;
ORA-01403: no data found
If this query is part of a stored procedure and is called from Hibernate you will get this uninformative exception.
org.hibernate.exception.DataException: could not execute query
Oracle SQL, like many languages, has a try catch construct. In this example you could do the following.
BEGIN
SELECT status_date INTO v_status_date FROM member WHERE member_id = p_member_id_in;
EXCEPTION
WHEN NO_DATA_FOUND THEN
v_status_date := NULL;
END;
How to Log SQL on JBoss
by Frank Kim on Apr.04, 2006, under Hibernate, JBoss, JDBC, Logging
Edit the log4j.xml in the conf directory as shown below to turn on SQL debugging of the JDBC CMP plugin.
/apps/jboss/server/default/conf :->diff -c log4j.xml~ log4j.xml
*** log4j.xml~ Mon Sep 30 18:09:27 2002
--- log4j.xml Tue Apr 4 20:41:18 2006
***************
*** 61,73 ****
<!-- ============================== -->
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
! <param name="Threshold" value="INFO"/>
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\\n -->
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
</layout>
</appender>
--- 61,79 ----
<!-- ============================== -->
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
! <!--<param name="Threshold" value="INFO"/>-->
! <param name="Threshold" value="DEBUG"/>
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\\n -->
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
</layout>
+
+ <category name="org.jboss.ejb.plugins.cmp.jdbc">
+ <priority value="DEBUG"/>
+ </category>
+
</appender>
If you want to log Hibernate SQL statements:
<category name="org.hibernate.SQL">
<priority value="DEBUG"/>
</category>
If you want to log everything Hibernate’s doing, including SQL statements, schema export, transactions, etc.:
<category name="org.hibernate.SQL">
<priority value="DEBUG"/>
</category>