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>