the model : Insitution,Employer,Entity...
are "Contactable"
Set contactable.getContactInfos()
are mapped on different tables but the contactInfos are mapped to the same table (ptycon1).
the database
Employer -> thremp1
ContactInfo -> ptycon1
PostalAddress -> ptyadr1
so the contactinfos have multiple "many-to-one" column :
idInstitution,idEmployer,idEntity...
and the constraint is that every id* is null except one.
the problem
there's a trigger that verify that version number is always incremented :
PTYCON_BEFORE_UPDATE_GBP101.
so when i create an employer with contactInfos and save it, hibernate insert the employer, the contactinfo , the adress and the updates the contacInfos to set the idEmployer.
Code:
update ptycon1 set idEmployer=? where id=?
hibernates doesn't try to upgrade with the versionNumber and so the versionNumber is not incremented.
the solution ?the normal way to fix this in hibernate is to specify a "not-null" attribute on the foreign key : hibernate will not issue an update and insert directly the idEmployer.
But due to our "legacy" schema : multiple foreignkey and one not null. It's not working.
I understand why hibernate is not incrementing the versionNumber :
* all theses objects are created -> versionNumber=0
* the update occurs within the same transaction
Is there a possible mapping strategies to force hibernate to change the sql of the update to contains the incremented versionNumber ?
We want to avoid to relax or disable of the trigger...
thanks for any recommandation, feedback.
Hibernate version: 3.1.2
Mapping documents:Code between sessionFactory.openSession() and session.close():Full stack trace of any exception that occurs:Code:
org.hibernate.util.JDBCExceptionReporter SQL Error: -723, SQLState: 09000
org.hibernate.util.JDBCExceptionReporter [SQL0723] SQL trigger PTYCON_BEFORE_UPDATE_GBP101 in *N failed with SQLCODE -438 SQLSTATE 38501.
org.hibernate.event.def.AbstractFlushingEventListener Could not synchronize database state with session
AbstractFlush E org.hibernate.event.def.AbstractFlushingEventListener TRAS0014I: The following exception was logged org.hibernate.exception.GenericJDBCException: could not insert collection: [be.gfdi.ent.party.common.model.Employer.contactInfos#5000000000005]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)
Name and version of the database you are using:The generated SQL (show_sql=true):Code:
Hibernate: insert into thremp1 (techversionNumber, officialLanguage, fconcatenatedName, flanguage, fname, fshortName1, fshortName2, sconcatenatedName, slanguage, sname, sshortName1, sshortName2, endActivityDate, activity, affiliationQuarter, employeeNumberCode, rszCode, employerCategoryCode, uniqueEnterpriseNumber, rszNumber, rszNumberStartDate, partytype, uniqueNumber, matchCode, mergeCode, startDate, endDate, techcreationDate, techcreationUser, techlastUpdateDate, techlastUpdateUser, techCreationOrg, organization, updateOrganization, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, default)
Hibernate: select identity_val_local() from sysibm/sysdummy1
Hibernate: insert into ptycon1 (techversionNumber, contactInfoSequenceNumber, idInstitution, idOrganizationCoworker, idEmployer, idOrganizationEntity, idProvider, idClient, contactinfodescription, uniqueNumber, partyType, referenceNumber, contactinfotype, contactInfoStartDate, contactInfoEndDate, techcreationDate, techcreationUser, techlastUpdateDate, techlastUpdateUser, techCreationOrg, organization, updateOrganization, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, default)
Hibernate: select identity_val_local() from sysibm/sysdummy1
Hibernate: insert into ptyadr1 (techversionNumber, uniqueNumber, partyType, idContact, postalCode, municipality, street, countrycode, postaladdressstartdate, postaladdressenddate, wrongAddressCode, co, perAddress, fresidence, sresidence, secondCo, secondPerAddress, contactinfotype, contactInfoSequenceNumber, organization, updateOrganization, techcreationDate, techcreationUser, techlastUpdateDate, techlastUpdateUser, techCreationOrg, lng, boxNumber, district, number, postalCodeSequenceNumber, streetCode, addressType, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '01', default)
Hibernate: select identity_val_local() from sysibm/sysdummy1
Hibernate: update ptycon1 set idEmployer=? where id=?
Debug level Hibernate log excerpt: