@@ -164,6 +164,19 @@ public static bool IsNotTransient(string entityName, System.Object entity, bool?
164
164
return ! IsTransient ( entityName , entity , assumed , session ) ;
165
165
}
166
166
167
+
168
+ /// <summary>
169
+ /// Is this instance persistent or detached?
170
+ /// </summary>
171
+ internal static bool ? IsNotTransient ( string entityName , object entity , ISessionImplementor session )
172
+ {
173
+ if ( entity . IsProxy ( ) )
174
+ return true ;
175
+ if ( session . PersistenceContext . IsEntryFor ( entity ) )
176
+ return true ;
177
+ return ! IsTransient ( entityName , entity , session ) ;
178
+ }
179
+
167
180
/// <summary>
168
181
/// Is this instance, which we know is not persistent, actually transient?
169
182
/// If <tt>assumed</tt> is non-null, don't hit the database to make the
@@ -176,6 +189,24 @@ public static bool IsNotTransient(string entityName, System.Object entity, bool?
176
189
/// prepared to "recover" in the case that this assumed result is incorrect.
177
190
/// </remarks>
178
191
public static bool IsTransient ( string entityName , object entity , bool ? assumed , ISessionImplementor session )
192
+ {
193
+ var isUnsaved = IsTransient ( entityName , entity , session ) ;
194
+ if ( isUnsaved . HasValue )
195
+ return isUnsaved . Value ;
196
+ if ( assumed . HasValue )
197
+ // we use the assumed value, if there is one, to avoid hitting
198
+ // the database
199
+ return assumed . Value ;
200
+ return IsPersisted ( entityName , entity , session ) ;
201
+ }
202
+
203
+ /// <summary>
204
+ /// Is this instance, which we know is not persistent, actually transient?
205
+ /// If <tt>assumed</tt> is non-null, don't hit the database to make the
206
+ /// determination, instead assume that value; the client code must be
207
+ /// prepared to "recover" in the case that this assumed result is incorrect.
208
+ /// </summary>
209
+ public static bool ? IsTransient ( string entityName , object entity , ISessionImplementor session )
179
210
{
180
211
if ( Equals ( Intercept . LazyPropertyInitializer . UnfetchedProperty , entity ) )
181
212
{
@@ -190,16 +221,13 @@ public static bool IsTransient(string entityName, object entity, bool? assumed,
190
221
return isUnsaved . Value ;
191
222
192
223
// let the persister inspect the instance to decide
193
- IEntityPersister persister = session . GetEntityPersister ( entityName , entity ) ;
194
- isUnsaved = persister . IsTransient ( entity , session ) ;
195
- if ( isUnsaved . HasValue )
196
- return isUnsaved . Value ;
197
-
198
- // we use the assumed value, if there is one, to avoid hitting
199
- // the database
200
- if ( assumed . HasValue )
201
- return assumed . Value ;
224
+ var persister = session . GetEntityPersister ( entityName , entity ) ;
225
+ return persister . IsTransient ( entity , session ) ;
226
+ }
202
227
228
+ public static bool IsPersisted ( string entityName , object entity , ISessionImplementor session )
229
+ {
230
+ var persister = session . GetEntityPersister ( entityName , entity ) ;
203
231
if ( persister . IdentifierGenerator is Assigned )
204
232
{
205
233
// When using assigned identifiers we cannot tell if an entity
@@ -247,7 +275,7 @@ public static object GetEntityIdentifierIfNotUnsaved(string entityName, object e
247
275
return entity ;
248
276
/**********************************************/
249
277
250
- if ( IsTransient ( entityName , entity , false , session ) )
278
+ if ( IsTransient ( entityName , entity , session ) ?? false )
251
279
{
252
280
/***********************************************/
253
281
// TODO NH verify the behavior of NH607 test
0 commit comments