You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: migration-guide.adoc
+46Lines changed: 46 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -384,4 +384,50 @@ The integration of static metamodel generation in a project has changed; the rec
384
384
385
385
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].
386
386
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 )
0 commit comments