Basically, I have a trigger declared as instead insert on my database to check some constraints. If this trigger is enabled, is like hibernate cannot set the autogenerated (identity column on sql server) into the address object to persist it. If i disabled the trigger, all works well.
I'm using jTDS driver in case this makes a difference.
Hibernate version:2.1.18
Mapping documents:
person has a set of addresses. address maps back to person.
Code between sessionFactory.openSession() and session.close():
session.save(object);
session.flush();
Full stack trace of any exception that occurs:
Name and version of the database you are using:
SQL Server 2004
The generated SQL (show_sql=true):
Hibernate: insert into PERSON (_version, given_name, middle_name, surname, initi
als, US_citizen_ind, primary_email_address, person_oid, _oid_sequence, unpublish
ed_ind, _state, _locality, _created_timestamp, _created_by, _modified_timestamp,
_modified_by, _active_ind) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?)
Hibernate: insert into ADDRESS (_version, person_id, address_line_one, postal_co
de_1, country, state, locality, address_type, published_ind, _created_timestamp,
_created_by, _modified_timestamp, _modified_by, _active_ind) values (?, ?, ?, ?
, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Debug level Hibernate log excerpt:
2:26:09,364 WARN JDBCExceptionReporter:38 - SQL Error: 547, SQLState: 23000
2:26:09,364 ERROR JDBCExceptionReporter:46 - INSERT statement conflicted with C
LUMN FOREIGN KEY constraint 'FK_person2000'. The conflict occurred in database
PHINDIR_1.2.0', table 'person', column 'person_id'.
2:26:09,364 WARN JDBCExceptionReporter:38 - SQL Error: 547, SQLState: 23000
2:26:09,364 ERROR JDBCExceptionReporter:46 - INSERT statement conflicted with C
LUMN FOREIGN KEY constraint 'FK_person2000'. The conflict occurred in database
PHINDIR_1.2.0', table 'person', column 'person_id'.
2:26:09,364 ERROR JDBCExceptionReporter:38 - could not insert: [gov.phindir.pla
form.common.transferObjects.Address]
ava.sql.SQLException: INSERT statement conflicted with COLUMN FOREIGN KEY const
aint 'FK_person2000'. The conflict occurred in database 'PHINDIR_1.2.0', table
person', column 'person_id'.
----------
FK_person2000 is the FK constraint on address.person_id column mapping to the person.person_id
|