Skip to content

Commit 7ea607a

Browse files
committed
HHH-18584 add to migration guide
Signed-off-by: Gavin King <[email protected]>
1 parent 0c1a1e9 commit 7ea607a

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

migration-guide.adoc

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,54 @@ String isDefault();
115115
----
116116

117117

118+
[[create-query]]
119+
== Queries with implicit `select` list and no explicit result type
120+
121+
In previous versions, Hibernate allowed a query with no `select` list to be passed to the overload of `createQuery()` with no explicit result type parameter, for example:
122+
123+
[source,java]
124+
List query =
125+
session.createQuery("from X, Y")
126+
.getResultList()
127+
128+
or:
129+
130+
[source,java]
131+
List query =
132+
session.createQuery("from X join y")
133+
.getResultList()
134+
135+
The select list was inferred based on the `from` clause.
136+
137+
In Hibernate 6 we decided to deprecate this overload of `createQuery()`, since:
138+
139+
- it returns a raw type, resulting in compiler warnings in client code, and
140+
- the second query is truly ambiguous, with no obviously intuitive interpretation.
141+
142+
As of Hibernate 7, the method is remains deprecated, and potentially-ambiguous queries _are no longer accepted_.
143+
Migration paths include:
144+
145+
1. explicitly specify the `select` list,
146+
2. add `X.class` or `Object[].class` as a second argument, to disambiguate the interpretation of the query, or
147+
3. in the case where the query should return exactly one entity, explicitly assign the alias `this` to that entity.
148+
149+
For example, the queries above may be migrated via:
150+
151+
[source,java]
152+
List<Object[]> result =
153+
session.createQuery("from X, Y", Object[].class)
154+
.getResultList()
155+
156+
or:
157+
158+
[source,java]
159+
List<X> result =
160+
session.createQuery("from X join y", X.class)
161+
.getResultList()
162+
163+
118164
[[proxy-annotation]]
119-
== Replace @Proxy
165+
== Replace `@Proxy`
120166

121167
Applications will need to replace usages of the removed `@Proxy` annotation.
122168

0 commit comments

Comments
 (0)