Replies: 3 comments
-
That is the way to ensure IDs generated on DB's side are generated, with minimal impact on how the application work. (It would be slightly more optimal to do it only right before it gets actually needed, but depending on how your application works, it could be hard to know if it is needed or not, and where. Of course if the merged entities do not have DB's side generated IDs, the flush is then not needed.)
|
Beta Was this translation helpful? Give feedback.
-
You can restore old public class ForceSaveIdMergeEventListener : DefaultMergeEventListener
{
protected override object SaveWithGeneratedId(object entity, string entityName, object anything,
IEventSource source,
bool requiresImmediateIdAccess)
{
return base.SaveWithGeneratedId(entity, entityName, anything, source, requiresImmediateIdAccess: true);
}
} And to use it: //Somewhere before session factory is created:
NHibernate.Cfg.Configuration configuration = ...
configuration.EventListeners.MergeEventListeners = new[]{new ForceSaveIdMergeEventListener()}; Or via xml: <hibernate-configuration>
<session-factory>
...
<event type="merge">
<listener class="ForceSaveIdMergeEventListener"/>
</event>
</session-factory>
</hibernate-configuration> Similar fix can be applied for |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for your suggestions. We went with the Merge and force flush route since we didn't feel comfortable overriding the default merge behaviour due to future proofing reasons. Thanks 👍👍 |
Beta Was this translation helpful? Give feedback.
-
Since v.5.3 there was a breaking change:
"ISession.Persist will no more trigger immediate generation of identifier."
This have caused major issues for us, since we have lots of code that relies on the Id being present on the object after session.Merge(entity) has been called within a uncommited transaction.
Here is an issue posted by some other user explaining the issue:
#2632
What is the correct way of making it work like it used to (or equivalent)? Forcing flushes after merge? Using saveOrUpdate intead of merge?
This has made us really uneasy upgrading since this seem to affect our whole system and lots of business logic has broken down due to the missing id's.
Any help is much appreciated.
Beta Was this translation helpful? Give feedback.
All reactions