Hi,
I have so far been very successful with Hibernate and I'm very pleased with the results. The only thing I haven't been able to figure out is that if the generated Hibernate SQL is invalid (references a column that doesn't exist, has the wrong data type, or has invalid data, i.e. a NULL in a NOT NULL column) no exceptions are being thrown. The code I have is like this:
Code:
Connection conn = null;
Throwable anException;
try
{
// Using my own connection pool (no servlet container)
conn = ConnectionPool.getConnection( "myPool" );
// superclass method to abstract session logic
Session session = this.openSession( conn );
// Do hibernate stuff; save, update, delete
}
catch( Throwable t )
{
anException = t;
}
finally
{
try { this.closeSession( ); }
catch( Throwable t ) { }
try { ConnectionPool.freeConnection( "myPool", conn ); }
catch( Throwable t ) { }
}
if( anException != null )
{
throw( new PersistenceException( t ) );
}
// return values, if any
A few notes: all of my entity beans extend BusinessObject, which has static methods for opening and closing sessions using the ThreadLocal stuff in the documentation, with a few tweaks to account for the fact that a session is opened and closed for every operation. I'm maintaining the "saved" state in a property on BusinessObject and I explicitly call save( ) or update( ) depending on its value (and then set the value accordingly). I have my reasons for this. Also, closeSession( ) does a flush( ) before closing the session. Finally, I've turned showSql on and I've seen the queries that are produced and I can verify that they contain errors (my fault, not Hibernate's).
I can fix the problems, but I would really like to know (in the form of an Exception, preferrably) when there is a problem and the database is not updated. Is it normal for Hibernate not to throw exceptions? Is there a setting in hibernate.cfg.xml or hibernate.properties that I can enable?
Thanks,
- Jesse