My problem is the following: I have a parent/child relationship between a List and an Entry: a List may contain multiple entries. Each time I had a new Entry to the list, Hibernate issues an update statement for each and every other entry in the list, whic is a performance kill (some lists may have thousands of entries).
Any idea what's going wrong here?
My configuration is the following:
Hibernate version:3.0.5
Mapping documents: The relation is bidirectional:
Parent: <hibernate-mapping> <class ... name="com.viveo.rtcc.plugins.gis.server.domainmodel.List" <set name="entries" inverse="true" cascade="all-delete-orphan" lazy="true"> <key column="FK_GIS_LIST"/> <one-to-many class="com.viveo.rtcc.plugins.gis.server.domainmodel.Entry"/> </set> ... </hibernate-mapping>
Child: <hibernate-mapping> <class ... name="com.viveo.rtcc.plugins.gis.server.domainmodel.Entry" <many-to-one name="list" column="FK_GIS_LIST" class="com.viveo.rtcc.plugins.gis.server.domainmodel.List" not-null="true" /> ... </hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Entry entry = createAndInitializeNewEntry();
List list = (List) session.get(List.class, aListId);
entry.setList(list);
list.getEntries().add(entry); // getEntries returns the Set of entries
Full stack trace of any exception that occurs:
Name and version of the database you are using: IBM DB2
The generated SQL (show_sql=true):
Hibernate: insert into TXXXGIS_ENTRY (TYPE, NAME, SURNAME, HONORIFIC, CHIPS_UID, SWIFT_IDENTIFIER, IS_DANGEROUS, SDN_CATEGORY, PERMUTATION_GEN, ENTRY_FACPLUS_ID, NAT_ID, ORIGINAL_ID, AFF_CODE, IS_DELETED, FED, STATUS, IMPORT_FLAG, FK_GIS_LIST, FK_ENRICHMENT, PK_GIS_ENTRY) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: update TXXXGIS_LIST set LIST_TYPE=?, LIST_NAME=?, LIST_DESCRIPTION=?, PROJECT_ID=?, FK_MANDATOR_ID=? where PK_GIS_LIST=?
Hibernate: update TXXXGIS_ENTRY set TYPE=?, NAME=?, SURNAME=?, HONORIFIC=?, CHIPS_UID=?, SWIFT_IDENTIFIER=?, IS_DANGEROUS=?, SDN_CATEGORY=?, PERMUTATION_GEN=?, ENTRY_FACPLUS_ID=?, NAT_ID=?, ORIGINAL_ID=?, AFF_CODE=?, IS_DELETED=?, FED=?, STATUS=?, IMPORT_FLAG=?, FK_GIS_LIST=?, FK_ENRICHMENT=? where PK_GIS_ENTRY=? Hibernate: update TXXXGIS_ENTRY set TYPE=?, NAME=?, SURNAME=?, HONORIFIC=?, CHIPS_UID=?, SWIFT_IDENTIFIER=?, IS_DANGEROUS=?, SDN_CATEGORY=?, PERMUTATION_GEN=?, ENTRY_FACPLUS_ID=?, NAT_ID=?, ORIGINAL_ID=?, AFF_CODE=?, IS_DELETED=?, FED=?, STATUS=?, IMPORT_FLAG=?, FK_GIS_LIST=?, FK_ENRICHMENT=? where PK_GIS_ENTRY=?
...
Hibernate: update TXXXGIS_ENTRY set TYPE=?, NAME=?, SURNAME=?, HONORIFIC=?, CHIPS_UID=?, SWIFT_IDENTIFIER=?, IS_DANGEROUS=?, SDN_CATEGORY=?, PERMUTATION_GEN=?, ENTRY_FACPLUS_ID=?, NAT_ID=?, ORIGINAL_ID=?, AFF_CODE=?, IS_DELETED=?, FED=?, STATUS=?, IMPORT_FLAG=?, FK_GIS_LIST=?, FK_ENRICHMENT=? where PK_GIS_ENTRY=?
Debug level Hibernate log excerpt:
|