Skip to content

Commit adb125b

Browse files
dreab8beikov
authored andcommitted
HHH-16994 migration guide update
1 parent 15fd989 commit adb125b

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

migration-guide.adoc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,4 +384,50 @@ The integration of static metamodel generation in a project has changed; the rec
384384

385385
Check out the specific sections in the User Guide for a guideline on how to do this for {userGuideBase}#tooling-gradle-modelgen[Gradle] or {userGuideBase}#tooling-maven-modelgen[Maven].
386386

387+
[[mative-query]]
388+
== Native query with joins
389+
390+
A Native query that uses a result set mapping, explicit or implicitly by specifying an entity class as result type to `createNativeQuery`,
391+
requires unique select item aliases.
392+
If the native query contains a join to a table with same named columns, a query that e.g. does `select * from ..` will lead to an error.
393+
If the desire is to select only columns for the result type entity, prefix the * with a tables alias e.g.
394+
`select p.* from ...`
395+
396+
397+
E.g.
398+
399+
```
400+
@Entity
401+
class Person {
402+
@Id
403+
private Long id;
404+
405+
@OneToMany(mappedBy = "person")
406+
private Set<Dog> dogs = new HashSet<>( 0 );
407+
}
408+
409+
@Entity
410+
class Dog {
411+
@Id
412+
private Long id;
413+
}
414+
```
415+
416+
Queries like
417+
418+
```
419+
session.createNativeQuery(
420+
"SELECT * FROM person p LEFT JOIN dog d on d.person_id = p.id", Person.class )
421+
.getResultList();
422+
```
423+
424+
have to be changed to
425+
426+
```
427+
session.createNativeQuery(
428+
"SELECT p.* FROM person p LEFT JOIN dog d on d.person_id = p.id", Person.class )
429+
.getResultList();
430+
```
431+
432+
387433

0 commit comments

Comments
 (0)