jakartaee / persistence

https://jakartaee.github.io/persistence/
Other
203 stars 59 forks source link

named queries, entity graphs, and result set mappings in static metamodel generation #459

Closed gavinking closed 1 year ago

gavinking commented 1 year ago

A very nice—and extremely underused—feature of the static metamodel is the ability to write:

@OneToMany(mappedBy=Item_.ORDER)
Set<Item> items;

which is a lot more typesafe than:

@OneToMany(mappedBy="order")
Set<Item> items;

But we could take this further. We could have the static metamodel include string-valued constants for named queries, named entity graphs, and even SQL result set mappings.

So you could write, for example:

em.createQuery(Book_.QUERY_ALL_BOOKS).getResultList();

Hibernate 6.3 already supports this.

gavinking commented 1 year ago

Oh, wait, I messed up in describing this.

A very nice—and extremely underused—feature of the static metamodel

Actually that "very nice" feature is a feature of our implementation, which is not actually mandated by section 6.2.1.1 of the specification.

But it should be!

gavinking commented 1 year ago

Please check out this proposal: https://github.com/jakartaee/persistence/pull/461/commits/ff3f6f9328333cd75004254d4ec54b07c31dc22d