Hi(bernate),
I use OracleDialect for inserting into database with native ID generation.
If I violate a not-null constraint, Hibernate (not the database) correctly
throws an Exception. I do tx.rollback() then, but my POJO still contains
automatically assigned ID (sequence). This means, it order to get it saved
"next time", I have to manually set all my IDs back to null, which is not
nice. I assume this is a rollback bug which probably occurs with all kind
of Oracle database errors, not only with not-null violations which are
detected by hibernate. The problem does not occur with HSQL, I think this
is because the autoincrement strategy works differently.
Btw, should the SessionImpl#checkNullability(..) not be done BEFORE the
sequence is requested from the database?
this is my reduced mapping file:
<class name="my.TrackedHttpRequest" table="TRACKED_HTTP_REQUEST">
<id
column="ID"
name="id"
type="long"
unsaved-value="null"
>
<generator class="native" />
</id>
<many-to-one name="session"
class="my.TrackedSession"
column="SESSION_ID"
cascade="save-update"
not-null="true" />
[...]
</class>
this is my testcase:
public void testStoreSingleTrackedHttpRequestMisuse() throws HibernateException
{
// create new business object which violates not-null constraint
TrackedHttpRequest newRequest =
TrackingMockObjectsFactory.createDummyTrackedHttpRequest();
// ensure no primary key set
assertNull( newRequest.getId() );
Session session = sessionFactory.openSession();
Transaction tx = null;
try
{
tx = session.beginTransaction();
session.saveOrUpdate(aRequest);
tx.commit();
fail("Not-null-constraint NOT detected!");
}
catch (HibernateException hex)
{
if (tx != null)
{
tx.rollback();
}
assertNull( newRequest.getId() );
throw hex;
}
finally
{
session.close();
}
}
The assertNull-check after the tx.rollback() fails for Oracle.
Regards,
Jonas
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel