-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Catching HibernateSystemException
PostPosted: Fri Sep 29, 2006 6:24 am 
Newbie

Joined: Fri Sep 29, 2006 6:08 am
Posts: 5
Hi,

I have an object that i want to save into a SQL Server database. Via the following method

Code:
    public void saveLTS(LongTermSession lts)
       throws DataAccessException {
       getHibernateTemplate().saveOrUpdate(lts);
    }


The object has an id column, the value of this is populated by SQL Server (using Identity = Yes in the database schema).

My problem arises when one of our DBAs has to turn the Identity value to "No" - this happens from time to time due to replication problems.

The point is that the information that we are collecting is not vital, I dont want the application to completely fall over if it cant insert a new object.

But at present I seem to get the following, seemingly uncatchable Hibernate error



Code:
2006-09-29 10:55:07,433 - ERROR (org.hibernate.util.JDBCExceptionReporter:72) - Cannot insert the value NULL into column 'lts_id', table 'dbWeb.dbo.tblLongTermSessions'; column does not allow nulls. INSERT fails.
2006-09-29 10:55:07,449 - ERROR (org.apache.catalina.core.StandardWrapperValve:260) - Servlet.service() for servlet springFrontController threw exception
org.springframework.orm.hibernate3.HibernateSystemException: not-null property references a null or transient value: com.qas.newmedia.internet.core.lts.model.LongTermSessionEntry.longTermSession; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: com.qas.newmedia.internet.core.lts.model.LongTermSessionEntry.longTermSession
org.hibernate.PropertyValueException: not-null property references a null or transient value: com.qas.newmedia.internet.core.lts.model.LongTermSessionEntry.longTermSession
   at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)



Can somebody tell me how i can catch this errors?

Thanks in advance for any help


Hibernate version:
3

Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
   schema="dbWeb.dbo"
   default-cascade="none"
   default-access="property"
   default-lazy="true"
   auto-import="true"
   package="com.qas.newmedia.internet.core.lts.model">

   <class
      name="LongTermSession"
      table="tblLongTermSessions"
      lazy="true">

        <id name="id" type="int" column="lts_id" unsaved-value="0">
           <generator class="identity" />
       </id>

      <property name="created" column="created" type="calendar" not-null="true" />
      <property name="webAbacusId" column="wa_id" type="string" not-null="true" unique="true" />
      <property name="siteName" column="site_name" type="string" not-null="true" />
      <property name="userAgent" column="user_agent" type="string" not-null="true" />

      <list name="entries" inverse="true" lazy="true" cascade="all">
         <key column="lts_id"/>
         <list-index column="lts_entry_id" />
         <one-to-many class="LongTermSessionEntry" /> 
      </list>
      
   </class>
   
</hibernate-mapping>


Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
   schema="dbWeb.dbo"
   default-cascade="none"
   default-access="property"
   default-lazy="true"
   auto-import="true"
   package="com.qas.newmedia.internet.core.lts.model">

   <class
      name="LongTermSessionEntry"
      table="tblLongTermSessionEntries"
      lazy="true">

        <id name="id" type="int" column="lts_entry_id" unsaved-value="0">
           <generator class="identity" />
       </id>

      <property name="created" column="created" type="calendar" not-null="true" />
      <property name="siteName" column="site_name" type="string" not-null="true" />      
      <property name="remoteAddress" column="remote_address" type="string" not-null="true" />
      <property name="remoteHost" column="remote_host" type="string" not-null="true" />      
      <property name="key" column="attr_key" type="string" not-null="false" />
      <property name="value" column="attr_value" type="string" not-null="false" />
      <property name="type" column="attr_type" type="string" not-null="true" />            

      <many-to-one
            name="longTermSession"
            column="lts_id"
            not-null="true" />   

   </class>
   
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 30, 2006 9:56 am 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
HibernateSystemException is a RuntimeException:

http://www.springframework.org/docs/api/org/springframework/orm/hibernate3/HibernateSystemException.html

If you want to catch this exception, you will have to write appropriate code for doing the same. Something like:

Code:
public void saveLTS(LongTermSession lts)    throws DataAccessException {

       try {
            getHibernateTemplate().saveOrUpdate(lts);
       } catch(HibernateSystemException hse) {
             //do whatever
       }
    }


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 24, 2006 12:05 pm 
Newbie

Joined: Fri Sep 29, 2006 6:08 am
Posts: 5
Hi,

Thanks for your response.

The problem with using Spring is that we dont actually have a handle on the actual objects until we hit our top level controllers since Spring gives us a proxy instead.

Hence I cannot catch the HibernateExceptions at the level you suggest.

What i am trying to say is that these are Hibernate and hence DAO errors but the only way i can deal with them in my code is to catch exceptions at the controller level when I am no longer dealing with a proxy.

Has anyone else found a way around this? We thought about extending the transaction manager?

Thanks

Matt


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.