[JIRA] (HHH-16730) joining @Any mappings
by Gavin King (JIRA)
Gavin King ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZWUxMGVjODU5... ) / Improvement ( https://hibernate.atlassian.net/browse/HHH-16730?atlOrigin=eyJpIjoiZWUxMG... ) HHH-16730 ( https://hibernate.atlassian.net/browse/HHH-16730?atlOrigin=eyJpIjoiZWUxMG... ) joining @Any mappings ( https://hibernate.atlassian.net/browse/HHH-16730?atlOrigin=eyJpIjoiZWUxMG... )
Issue Type: Improvement Assignee: Unassigned Created: 31/May/2023 15:20 PM Priority: Major Reporter: Gavin King ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
So I’ve just woken up to how hard it really is to do something like join fetch an @Any mapping.
I got some distance with this by mapping the association @Any(fetch=LAZY) , and then using a query like this:
select n, p from N n join P p on n.thing.id = p.id
And then as long as I remember to force-initialize n.thing before the tx ends, it essentially works.
There’s three things wrong with this:
* it’s pretty verbose,
* I have to explicitly force-initialize the proxies, and
* if I switch to @Any(fetch=EAGER) (which is the default, ugh) then I start getting n+1 selects.
So, damn, it would sure be nice to be able to write things like:
select n, t from N n join n.thing t
select n from N n join fetch n.thing
select n, p from N n join treat (n.thing as P) p
select n from N n join fetch treat (n.thing as P)
But I would say the highest priority would be to simply fix the problem that fetch=EAGER automatically results in extra unnecessary selects.
( https://hibernate.atlassian.net/browse/HHH-16730#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16730#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:a994ca2 )
1 year, 6 months
[JIRA] (HHH-16729) Instantiate a proxy of the correct class for ManyToOne associated to an inheritance hierarchy
by Guillaume Toison (JIRA)
Guillaume Toison ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3... ) *commented* on HHH-16729 ( https://hibernate.atlassian.net/browse/HHH-16729?atlOrigin=eyJpIjoiYWNlOW... )
Re: Instantiate a proxy of the correct class for ManyToOne associated to an inheritance hierarchy ( https://hibernate.atlassian.net/browse/HHH-16729?atlOrigin=eyJpIjoiYWNlOW... )
Thanks for replying, I am aware of Hibernate.isInstance() and Hibernate.unproxy() methods but if possible I’d like to be able to write idiomatic Java code, for instance:
if (food instanceof Cheese cheese) {
// use the cheese
}
Instead of:
if (Hibernate.isInstance(food, Cheese.class)) {
Cheese cheese = Hibernate.unproxy(food, Cheese.class);
// use the cheese
}
One benefit of having the right class is that we wouldn’t need to trigger a load if we just need an instanceof test.
I’ve got to admit that I’m not familiar with @Any so I’ll look into that 👍
Some of the associations I have are collections fetched using the new `@SQLSelect` so I’m sure sure if that scenario would be supported.
Assuming that item now needs a discriminator, I would need to tell Hibernate where that new column would be, but JPA’s @FieldResult ` does not support it, right?
@SqlResultSetMapping(name="OrderResults",
entities={
@EntityResult(entityClass=com.acme.Order.class, fields={
@FieldResult(name="id", column="order_id"),
@FieldResult(name="quantity", column="order_quantity"),
@FieldResult(name="item", column="order_item")})
})
( https://hibernate.atlassian.net/browse/HHH-16729#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16729#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:a994ca2 )
1 year, 6 months