简体   繁体   中英

IStatelessSession insert object with many-to-one

I've got common mapping

<class name="NotSyncPrice, Portal.Core" table='Not_sync_price'>
<id name="Id" unsaved-value="0">
  <column name="id" not-null="true"/>
  <generator class="native"/>
</id>
<many-to-one name="City" class="Clients.Core.Domains.City, Clients.Core" column="city_id"
             cascade="none"></many-to-one>
<!--<property name="City">
  <column name="city_id"/>
</property>-->

I want to use IStatelessSession for batch insert. But when i set city object to NotSyncPrice object and call IStatelessSession I've got strange exception:

NHibernate.Impl.StatelessSessionImpl.get_Timestamp()

When its null or int all is ok. I try use real && proxy city object. But no result. What's wrong:( Please help

This could be because of cacheable attribute. If you have marked this entity or the loading criteria query to be cacheable, then it cannot be loaded using a stateless session.

I had the same problem.

The cause were entities whose mapping contained the <cache> element.

These entities were primarily used in a web application. Secondlevel caching was introduced in order to introduce performance in the web application.

But a standalone admin application was performing bulk load with the same entities using stateless sessions and the same entities. Now, stateless session does not work with cachable entities.

A simple solution was to explicitly switch off secondlevel cache altogether in the admin application. This can be done programmatically or with the hibernate config file by including the following line:

<property name="cache.use_second_level_cache">false</property>

This solved the problem without having to remove the <cache> elements in the mapping files or creating a separate mapping for admin application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM