Using Hibernate version 2.1.2, I'm executing the following code:
Session session = this.sessionFactory.openSession();
Transaction tx = session.beginTransaction();
theGroup = (PersistentEnumValueGroup)session.load( PersistentEnumValueGroup.class, new Integer(3) );
PersistentEnumValue theEnumValue = new PersistentEnumValue();
theEnumValue.setGroupId( theGroup.getId() );
theEnumValue.setCode( new Integer(1) );
theGroup.getEnumValues().add( theEnumValue );
theEnumValue = new PersistentEnumValue();
theEnumValue.setGroupId( theGroup.getId() );
theEnumValue.setCode( new Integer(2) );
theGroup.getEnumValues().add( theEnumValue );
session.update( theGroup );
tx.commit();
session.close();
And I get the following output:
13:24:25,139 DEBUG BasicCollectionPersister:567 - Deleting rows of collection: [com.freddiemac.ads.persistence.PersistentEnumValueGroup.enumValues#3]
13:24:25,139 DEBUG BasicCollectionPersister:592 - no rows to delete
13:24:25,139 DEBUG BasicCollectionPersister:732 - Updating rows of collection: com.freddiemac.ads.persistence.PersistentEnumValueGroup.enumValues#3
13:24:25,139 DEBUG BasicCollectionPersister:737 - done updating rows: 0 updated
13:24:25,149 DEBUG BasicCollectionPersister:606 - Inserting rows of collection: [com.freddiemac.ads.persistence.PersistentEnumValueGroup.enumValues#3]
13:24:25,149 DEBUG BatcherImpl:196 - about to open: 0 open PreparedStatements, 0 open ResultSets
13:24:25,149 DEBUG SQL:237 - update ENUM_VAL set id_enum_val_grp=? where id_enum_val_grp=? and cd_enum_val=?
13:24:25,149 DEBUG BatcherImpl:241 - preparing statement
13:24:25,149 DEBUG IntegerType:46 - binding '3' to parameter: 1
13:24:25,149 DEBUG Cascades:331 - id unsaved-value strategy NONE
13:24:25,149 DEBUG IntegerType:46 - binding '3' to parameter: 2
13:24:25,159 DEBUG IntegerType:46 - binding '2' to parameter: 3
13:24:25,159 ERROR SessionImpl:2343 - Could not synchronize database state with session
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
Why is Hibernate trying to do an update when it should be doing an insert?
|