|
|
Multiple inserts for one object on a single save
hello all,
I thought this was a collection problem, but it isnt. Basically I noticed that a single save on an object was causing multiple sql inserts. I commented everything out of my domain object mapping except its id, which uses the assigned generator.
In my dao i call
getHibernateTemplate.save()
getHibernateTemplate.flush()
and I see five inserts. I am using HibernateTransactionManager and springs abstractdependencyblahblahblah class -- the flush is only so I can use JdbcTemplate to verify via jdbc what is in the db.
any ideas?
here is the configsCode:
lt;class name=quot;Gamequot; table=quot;Gamequot;gt;
lt;id name=quot;gameNumberquot; column=quot;gameNumberquot;/gt;
lt;/classgt;lt;bean id=quot;gameInfoSessionFactoryquot;
class=quot;org..orm.hibernate3.LocalSessionFactoryBeanquot;gt;
lt;property name=quot;mappingResourcesquot;gt;
lt;listgt;
lt;valuegt;myfile.hbm.xmllt;/valuegt;
lt;/listgt;
lt;/propertygt;
lt;property name=quot;hibernatePropertiesquot;gt;
lt;propsgt;
lt;prop key=quot;show_sqlquot;gt;truelt;/propgt;
lt;prop key=quot;hibernate.dialectquot;gt;
org.hibernate.dialect.HSQLDialectlt;/propgt;
lt;!--prop key=quot;hbm2ddl.autoquot;gt;createlt;/prop--gt;
lt;!--prop key=quot;current_session_context_classquot;gt;createlt;/prop--gt;
lt;prop key=quot;hibernate.cache.provider_classquot;gt;
org.hibernate.cache.EhCacheProvider lt;/propgt;
lt;!--prop key=quot;hibernate.autocommitquot;gt;falselt;/prop--gt;
lt;prop key=quot;hibernate.show_sqlquot;gt;truelt;/propgt;
lt;/propsgt;
lt;/propertygt;
lt;property name=quot;dataSourcequot; ref=quot;gameInfoDataSourcequot;/gt;
lt;/beangt;
lt;bean id=quot;gameInfoDataSourcequot;
class=quot;org..jdbc.datasource.DriverManagerDataSourcequot;gt;
lt;property name=quot;driverClassNamequot;gt;
lt;valuegt;org.hsqldb.jdbcDriverlt;/valuegt;
lt;/propertygt;
lt;property name=quot;uclquot;gt;
lt;valuegt;jdbc:hsqldb:mem:wtllt;/valuegt;
lt;/propertygt;
lt;property name=quot;usernamequot;gt;
lt;valuegt;salt;/valuegt;
lt;/propertygt;
lt;property name=quot;passwordquot;gt;
lt;valuegt;lt;/valuegt;
lt;/propertygt;
lt;/beangt;
lt;bean id=quot;transactionManagerquot;
class=quot;org..orm.hibernate3.HibernateTransactionManagerquot;gt;
lt;property name=quot;sessionFactoryquot;gt;
lt;ref local=quot;gameInfoSessionFactoryquot;/gt;
lt;/propertygt;
lt;/beangt;Maybe you have cascades turned on.
as you can see from the mapping, i do not have cascades (unless it is a default).
I should say I am seeing this in a unit test. I noticed that whenever I saved the reference to the previously transient instance started having duplicate instances in its collections. I thought it was a collection mapping problem, so I started commenting out the collection mappings in the parent object. I think I left the many-to-one designation in the child class even though the parent (game) only has an id.
the point of all that: I *did* have cascades on the collections. |
|