-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
typesafe way to pass options and an EntityGraph to find() #383
Comments
There's a similar, related problem with |
Actually, scratch that, a better design would probably be a
and then add an overload with the signature:
So this |
So, after quite a lot of reflection on this, I'm now inclined to go for something much more like how Hibernate does this, but with cleaned-up naming. I generally prefer You see, the tricky part of this is passing the Consider: var graph = entityManager.createEntityGraph(Book.class);
graph.addSubgraph(Book_.publisher);
Book book =
entityManager.find(Book.class)
.fetching(graph)
.with(lockModeType)
.with(cacheStoreMode)
.withTimout(2000)
.get(id); This is all nice and typesafe, and only requires adding one new interface Now, I guess I can make it work with var graph = entityManager.createEntityGraph(Book.class);
graph.addSubgraph(Book_.publisher);
var options = // this is a FindOptions<Book>
graph.fetch()
.with(lockModeType)
.with(cacheStoreMode)
.withTimeout(2000);
Book book = entityManager.find(Book.class, id, options); And the signature would be:
And there would also be a way to obtain a var options = // this is a FindOptions<Object>
entityManager.options()
.with(lockModeType)
.with(cacheStoreMode)
.withTimeout(2000); So it works, I guess. But that just seems a bit more complex for no real advantage. |
I mean, look, the following variation works, and I don't hate it, but it still doesn't seem better: var graph = entityManager.createEntityGraph(Book.class);
graph.addSubgraph(Book_.publisher);
var options = // this is a FindOptions<Book>
FindOptions.fetching(graph)
.with(lockModeType)
.with(cacheStoreMode)
.withTimeout(2000);
Book book = entityManager.find(Book.class, id, options); var options = // this is a FindOptions<Object>
FindOptions.create()
.with(lockModeType)
.with(cacheStoreMode)
.withTimeout(2000);
Book book = entityManager.find(Book.class, id, options); |
Folks, please review the new API proposed in https://github.com/jakartaee/persistence/pull/415/files. |
instead of calling it find() in one place See jakartaee#383
Everyone, please take a look at my proposed API in #436. |
@lukasj has suggested a different approach, modeled on
So we will:
This has the advantage that it's quite extensible by providers. |
Also introduce operations for defining Graphs so that the external differentiation between "fetch graphs" and "load graphs" is no longer needed. see jakartaee#383.
Okay, folks, the approach taken in #454 is:
With this proposal you can write: Book book = em.find(Book.class, bookId,
PESSIMISTIC_WRITE,
CacheStoreMode.BYPASS,
Timeout.ms(200)); And, even better: var bookGraph = em.createEntityGraph(Books.class);
bookGraph.addAttributeNode(Book_.authors);
Book book = em.find(bookGraph, bookId,
PESSIMISTIC_WRITE,
CacheStoreMode.BYPASS); The graph is treated as a "load graph". Now, the issue with that is that there's no way to suppress loading of associations mapped |
I mean, the simplest possible solution would be to just add Another possibility would be to add
|
The purpose of these operations is to suppress defaulted EAGER association loading in load graphs, but it can be used more broadly to suppress loading of any graph node. see jakartaee#383.
OK, so, how about adding these methods to allow you to suppress association loading in a load graph. |
The purpose of these operations is to suppress defaulted EAGER association loading in load graphs, but it can be used more broadly to suppress loading of any graph node. see jakartaee#383.
The purpose of these operations is to suppress defaulted EAGER association loading in load graphs, but it can be used more broadly to suppress loading of any graph node. see jakartaee#383.
The purpose of these operations is to suppress defaulted EAGER association loading in load graphs, but it can be used more broadly to suppress loading of any graph node. see jakartaee#383.
We need to decide whether |
The purpose of these operations is to suppress defaulted EAGER association loading in load graphs, but it can be used more broadly to suppress loading of any graph node. see jakartaee#383.
The purpose of these operations is to suppress defaulted EAGER association loading in load graphs, but it can be used more broadly to suppress loading of any graph node. see jakartaee#383.
The purpose of these operations is to suppress defaulted EAGER association loading in load graphs, but it can be used more broadly to suppress loading of any graph node. see jakartaee#383.
The purpose of these operations is to suppress defaulted EAGER association loading in load graphs, but it can be used more broadly to suppress loading of any graph node. see jakartaee#383.
The purpose of these operations is to suppress defaulted EAGER association loading in load graphs, but it can be used more broadly to suppress loading of any graph node. see #383.
Currently, setting the
CacheStoreMode
orCacheRetrieveMode
requires the use of string typing, thejakarta.persistence.cache.retrieveMode
orjakarta.persistence.cache.storeMode
properties.This is obviously bad, and therefore:
setCacheStoreMode()
andsetCacheRetrieveMode()
toEntityManager
and toQuery
.CacheStoreMode
,CacheRetrieveMode
, andLockModeType
, calling itFindOption
, for example, along with new overloads offind()
andrefresh()
with signatureT find(Class<T> entityClass, Object primaryKey, FindOption... options)
.The text was updated successfully, but these errors were encountered: