15
15
16
16
import jakarta .persistence .CacheRetrieveMode ;
17
17
import jakarta .persistence .CacheStoreMode ;
18
- import jakarta .persistence .ConnectionConsumer ;
19
- import jakarta .persistence .ConnectionFunction ;
20
18
import jakarta .persistence .EntityGraph ;
21
19
import jakarta .persistence .EntityManager ;
22
20
import jakarta .persistence .FlushModeType ;
@@ -194,6 +192,7 @@ public interface Session extends SharedSessionContract, EntityManager {
194
192
*
195
193
* @throws HibernateException if changes could not be synchronized with the database
196
194
*/
195
+ @ Override
197
196
void flush ();
198
197
199
198
/**
@@ -205,7 +204,7 @@ public interface Session extends SharedSessionContract, EntityManager {
205
204
*
206
205
* @param flushMode the new {@link FlushModeType}
207
206
*
208
- * @see #setHibernateFlushMode(FlushMode) for additional options
207
+ * @see #setHibernateFlushMode(FlushMode)
209
208
*/
210
209
@ Override
211
210
void setFlushMode (FlushModeType flushMode );
@@ -232,6 +231,8 @@ public interface Session extends SharedSessionContract, EntityManager {
232
231
* Get the current {@linkplain FlushModeType JPA flush mode} for this session.
233
232
*
234
233
* @return the {@link FlushModeType} currently in effect
234
+ *
235
+ * @see #getHibernateFlushMode()
235
236
*/
236
237
@ Override
237
238
FlushModeType getFlushMode ();
@@ -267,6 +268,7 @@ public interface Session extends SharedSessionContract, EntityManager {
267
268
*
268
269
* @since 6.2
269
270
*/
271
+ @ Override
270
272
CacheStoreMode getCacheStoreMode ();
271
273
272
274
/**
@@ -276,6 +278,7 @@ public interface Session extends SharedSessionContract, EntityManager {
276
278
*
277
279
* @since 6.2
278
280
*/
281
+ @ Override
279
282
CacheRetrieveMode getCacheRetrieveMode ();
280
283
281
284
/**
@@ -287,6 +290,7 @@ public interface Session extends SharedSessionContract, EntityManager {
287
290
*
288
291
* @since 6.2
289
292
*/
293
+ @ Override
290
294
void setCacheStoreMode (CacheStoreMode cacheStoreMode );
291
295
292
296
/**
@@ -298,6 +302,7 @@ public interface Session extends SharedSessionContract, EntityManager {
298
302
*
299
303
* @since 6.2
300
304
*/
305
+ @ Override
301
306
void setCacheRetrieveMode (CacheRetrieveMode cacheRetrieveMode );
302
307
303
308
/**
@@ -474,9 +479,109 @@ public interface Session extends SharedSessionContract, EntityManager {
474
479
*/
475
480
void evict (Object object );
476
481
482
+ /**
483
+ * Return the persistent instance of the given entity class with the given identifier,
484
+ * or null if there is no such persistent instance. If the instance is already associated
485
+ * with the session, return that instance. This method never returns an uninitialized
486
+ * instance.
487
+ * <p>
488
+ * The object returned by {@code get()} or {@code find()} is either an unproxied instance
489
+ * of the given entity class, or a fully-fetched proxy object.
490
+ * <p>
491
+ * This operation requests {@link LockMode#NONE}, that is, no lock, allowing the object
492
+ * to be retrieved from the cache without the cost of database access. However, if it is
493
+ * necessary to read the state from the database, the object will be returned with the
494
+ * lock mode {@link LockMode#READ}.
495
+ * <p>
496
+ * To bypass the {@linkplain Cache second-level cache}, and ensure that the state of the
497
+ * requested instance is read directly from the database, either:
498
+ * <ul>
499
+ * <li>call {@link #find(Class, Object, FindOption...)}, passing
500
+ * {@link CacheRetrieveMode#BYPASS} as an option,
501
+ * <li>call {@link #find(Class, Object, LockMode)} with the explicit lock mode
502
+ * {@link LockMode#READ}, or
503
+ * <li>{@linkplain #setCacheRetrieveMode set the cache mode} to
504
+ * {@link CacheRetrieveMode#BYPASS} before calling this method.
505
+ * </ul>
506
+ *
507
+ * @apiNote This operation is very similar to {@link #get(Class, Object)}.
508
+ *
509
+ * @param entityType the entity type
510
+ * @param id an identifier
511
+ *
512
+ * @return a fully-fetched persistent instance or null
513
+ */
514
+ @ Override
515
+ <T > T find (Class <T > entityType , Object id );
516
+
517
+ /**
518
+ * Return the persistent instance of the given entity class with the given identifier,
519
+ * or null if there is no such persistent instance. If the instance is already associated
520
+ * with the session, return that instance. This method never returns an uninitialized
521
+ * instance. Obtain the specified lock mode if the instance exists.
522
+ * <p>
523
+ * Convenient form of {@link #find(Class, Object, LockOptions)}.
524
+ *
525
+ * @param entityType the entity type
526
+ * @param id an identifier
527
+ * @param lockMode the lock mode
528
+ *
529
+ * @return a fully-fetched persistent instance or null
530
+ *
531
+ * @since 7.0
532
+ *
533
+ * @see #find(Class, Object, LockOptions)
534
+ */
535
+ <T > T find (Class <T > entityType , Object id , LockMode lockMode );
536
+
537
+ /**
538
+ * Return the persistent instance of the given entity class with the given identifier,
539
+ * or null if there is no such persistent instance. If the instance is already associated
540
+ * with the session, return that instance. This method never returns an uninitialized
541
+ * instance. Obtain the specified lock mode if the instance exists.
542
+ *
543
+ * @param entityType the entity type
544
+ * @param id an identifier
545
+ * @param lockOptions the lock mode
546
+ *
547
+ * @return a fully-fetched persistent instance or null
548
+ *
549
+ * @since 7.0
550
+ */
551
+ <T > T find (Class <T > entityType , Object id , LockOptions lockOptions );
552
+
553
+ /**
554
+ * Return the persistent instances of the given entity class with the given identifiers
555
+ * as a list. The position of an instance in the returned list matches the position of its
556
+ * identifier in the given list of identifiers, and the returned list contains a null value
557
+ * if there is no persistent instance matching a given identifier. If an instance is already
558
+ * associated with the session, that instance is returned. This method never returns an
559
+ * uninitialized instance.
560
+ * <p>
561
+ * Every object returned by {@code findMultiple()} is either an unproxied instance of the
562
+ * given entity class, or a fully-fetched proxy object.
563
+ * <p>
564
+ * For more advanced cases, use {@link #byMultipleIds(Class)}, which returns an instance of
565
+ * {@link MultiIdentifierLoadAccess}.
566
+ *
567
+ * @param entityType the entity type
568
+ * @param ids the list of identifiers
569
+ * @param options options, if any
570
+ *
571
+ * @return an ordered list of persistent instances, with null elements representing missing
572
+ * entities, whose positions in the list match the positions of their ids in the
573
+ * given list of identifiers
574
+ * @see #byMultipleIds(Class)
575
+ * @since 7.0
576
+ */
577
+ <E > List <E > findMultiple (Class <E > entityType , List <Object > ids , FindOption ... options );
578
+
477
579
/**
478
580
* Read the persistent state associated with the given identifier into the given
479
581
* transient instance.
582
+ *
583
+ * @param object a transient instance of an entity class
584
+ * @param id an identifier
480
585
*/
481
586
void load (Object object , Object id );
482
587
@@ -524,6 +629,7 @@ public interface Session extends SharedSessionContract, EntityManager {
524
629
*
525
630
* @return an updated persistent instance
526
631
*/
632
+ @ Override
527
633
<T > T merge (T object );
528
634
529
635
/**
@@ -554,6 +660,7 @@ public interface Session extends SharedSessionContract, EntityManager {
554
660
*
555
661
* @param object a transient instance to be made persistent
556
662
*/
663
+ @ Override
557
664
void persist (Object object );
558
665
559
666
/**
@@ -635,6 +742,7 @@ public interface Session extends SharedSessionContract, EntityManager {
635
742
*
636
743
* @param object a persistent instance associated with this session
637
744
*/
745
+ @ Override
638
746
void refresh (Object object );
639
747
640
748
/**
@@ -688,39 +796,15 @@ public interface Session extends SharedSessionContract, EntityManager {
688
796
* saves, updates and deletions. Do not close open iterators or instances of
689
797
* {@link ScrollableResults}.
690
798
*/
799
+ @ Override
691
800
void clear ();
692
801
693
- /**
694
- * Return the persistent instances of the given entity class with the given identifiers
695
- * as a list. The position of an instance in the list matches the position of its identifier
696
- * in the given array, and the list contains a null value if there is no persistent instance
697
- * matching a given identifier. If an instance is already associated with the session, that
698
- * instance is returned. This method never returns an uninitialized instance.
699
- * <p>
700
- * Every object returned by {@code findMultiple()} is either an unproxied instance of the
701
- * given entity class, or a fully-fetched proxy object.
702
- * <p>
703
- * For more advanced cases, use {@link #byMultipleIds(Class)}, which returns an instance of
704
- * {@link MultiIdentifierLoadAccess}.
705
- *
706
- * @param entityType the entity type
707
- * @param ids the identifiers
708
- * @param options options, if any
709
- * @return an ordered list of persistent instances, with null elements representing missing
710
- * entities
711
- * @see #byMultipleIds(Class)
712
- * @since 7.0
713
- */
714
- <E > List <E > findMultiple (Class <E > entityType , List <Object > ids , FindOption ... options );
715
-
716
802
/**
717
803
* Return the persistent instance of the given entity class with the given identifier,
718
804
* or null if there is no such persistent instance. If the instance is already associated
719
805
* with the session, return that instance. This method never returns an uninitialized
720
806
* instance.
721
807
* <p>
722
- * This operation is very similar to {@link #find(Class, Object)}.
723
- * <p>
724
808
* The object returned by {@code get()} or {@code find()} is either an unproxied instance
725
809
* of the given entity class, or a fully-fetched proxy object.
726
810
* <p>
@@ -734,10 +818,12 @@ public interface Session extends SharedSessionContract, EntityManager {
734
818
* <ul>
735
819
* <li>call {@link #get(Class, Object, LockMode)} with the explicit lock mode
736
820
* {@link LockMode#READ}, or
737
- * <li>{@linkplain #setCacheMode(CacheMode) set the cache mode} to {@link CacheMode#IGNORE}
821
+ * <li>{@linkplain #setCacheMode set the cache mode} to {@link CacheMode#IGNORE}
738
822
* before calling this method.
739
823
* </ul>
740
824
*
825
+ * @apiNote This operation is very similar to {@link #find(Class, Object)}.
826
+ *
741
827
* @param entityType the entity type
742
828
* @param id an identifier
743
829
*
@@ -752,8 +838,8 @@ public interface Session extends SharedSessionContract, EntityManager {
752
838
* instance. Obtain the specified lock mode if the instance exists.
753
839
* <p>
754
840
* Convenient form of {@link #get(Class, Object, LockOptions)}.
755
- * <p>
756
- * This operation is very similar to {@link #find(Class, Object, jakarta.persistence. LockModeType)}.
841
+ *
842
+ * @apiNote This operation is very similar to {@link #find(Class, Object, LockModeType)}.
757
843
*
758
844
* @param entityType the entity type
759
845
* @param id an identifier
@@ -886,6 +972,7 @@ public interface Session extends SharedSessionContract, EntityManager {
886
972
*
887
973
* @since 6.0
888
974
*/
975
+ @ Override
889
976
<T > T getReference (T object );
890
977
891
978
/**
@@ -1026,15 +1113,6 @@ public interface Session extends SharedSessionContract, EntityManager {
1026
1113
*/
1027
1114
<T > NaturalIdMultiLoadAccess <T > byMultipleNaturalId (String entityName );
1028
1115
1029
- @ Override
1030
- Filter enableFilter (String filterName );
1031
-
1032
- @ Override
1033
- Filter getEnabledFilter (String filterName );
1034
-
1035
- @ Override
1036
- void disableFilter (String filterName );
1037
-
1038
1116
/**
1039
1117
* Get the {@linkplain SessionStatistics statistics} for this session.
1040
1118
*
@@ -1196,32 +1274,4 @@ public interface Session extends SharedSessionContract, EntityManager {
1196
1274
*/
1197
1275
@ Override @ Deprecated (since = "6.0" ) @ SuppressWarnings ("rawtypes" )
1198
1276
Query createQuery (CriteriaUpdate updateQuery );
1199
-
1200
-
1201
- @ Override
1202
- default <C > void runWithConnection (ConnectionConsumer <C > action ) {
1203
- doWork ( connection -> {
1204
- try {
1205
- //noinspection unchecked
1206
- action .accept ( (C ) connection );
1207
- }
1208
- catch (Exception e ) {
1209
- throw new RuntimeException ( e );
1210
- }
1211
- } );
1212
- }
1213
-
1214
- @ Override
1215
- default <C , T > T callWithConnection (ConnectionFunction <C , T > function ) {
1216
- return doReturningWork ( (connection ) -> {
1217
- try {
1218
- //noinspection unchecked
1219
- return function .apply ( (C ) connection );
1220
- }
1221
- catch (Exception e ) {
1222
- throw new RuntimeException ( e );
1223
- }
1224
- } );
1225
- }
1226
-
1227
1277
}
0 commit comments