|
44 | 44 | * <p>
|
45 | 45 | * At any given time, an instance may be associated with at most one open session.
|
46 | 46 | * <p>
|
47 |
| - * Any instance returned by {@link #get(Class, Object)} or by a query is persistent. |
| 47 | + * Any instance returned by {@link #get(Class, Object)}, {@link #find(Class, Object)}, |
| 48 | + * or by a query is persistent. A persistent instance might hold references to other |
| 49 | + * entity instances, and sometimes these references are <em>proxied</em> by an |
| 50 | + * intermediate object. When an associated entity has not yet been fetched from the |
| 51 | + * database, references to the unfetched entity are represented by uninitialized |
| 52 | + * proxies. The state of an unfetched entity is automatically fetched from the |
| 53 | + * database when a method of its proxy is invoked, if and only if the proxy is |
| 54 | + * associated with an open session. Otherwise, {@link #getReference(Object)} may be |
| 55 | + * used to trade a proxy belonging to a closed session for a new proxy associated |
| 56 | + * with the current session. |
48 | 57 | * <p>
|
49 | 58 | * A transient instance may be made persistent by calling {@link #persist(Object)}.
|
50 | 59 | * A persistent instance may be made detached by calling {@link #detach(Object)}.
|
@@ -969,6 +978,9 @@ public interface Session extends SharedSessionContract, EntityManager {
|
969 | 978 | * <p>
|
970 | 979 | * This operation is very similar to {@link #find(Class, Object)}.
|
971 | 980 | * <p>
|
| 981 | + * The object returned by {@code get()} or {@code find() } is either an unproxied instance |
| 982 | + * of the given entity class, of a fully-fetched proxy object. |
| 983 | + * <p> |
972 | 984 | * This operation requests {@link LockMode#NONE}, that is, no lock, allowing the object
|
973 | 985 | * to be retrieved from the cache without the cost of database access. However, if it is
|
974 | 986 | * necessary to read the state from the database, the object will be returned with the
|
@@ -1086,6 +1098,15 @@ public interface Session extends SharedSessionContract, EntityManager {
|
1086 | 1098 | * <p>
|
1087 | 1099 | * Note that {@link Hibernate#createDetachedProxy(SessionFactory, Class, Object)}
|
1088 | 1100 | * may be used to obtain a <em>detached</em> reference.
|
| 1101 | + * <p> |
| 1102 | + * It's sometimes necessary to narrow a reference returned by {@code getReference()} |
| 1103 | + * to a subtype of the given entity type. A direct Java typecast should never be used |
| 1104 | + * in this situation. Instead, the method {@link Hibernate#unproxy(Object, Class)} is |
| 1105 | + * the recommended way to narrow the type of a proxy object. Alternatively, a new |
| 1106 | + * reference may be obtained by simply calling {@code getReference()} again, passing |
| 1107 | + * the subtype. Either way, the narrowed reference will usually not be identical to |
| 1108 | + * the original reference, when the references are compared using the {@code ==} |
| 1109 | + * operator. |
1089 | 1110 | *
|
1090 | 1111 | * @param entityType the entity type
|
1091 | 1112 | * @param id the identifier of a persistent instance that exists in the database
|
|
0 commit comments