Skip to content
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

Default template of JPAQueryFactory differs from one provided by JPAQuery #398

Closed
TuomasKiviaho opened this issue Apr 17, 2013 · 6 comments
Closed
Milestone

Comments

@TuomasKiviaho
Copy link
Contributor

@TuomasKiviaho TuomasKiviaho commented Apr 17, 2013

#72 started for some reason to haunt me again and I figured out that JPAQueryFactory and JPAQuery constructors are not coherent on what templates to use as default. JPAQueryFactory always resolutes to JPQL standard template whereas JPAQuery is smart enough to seek advice from entity manager.

I think that the best solution would be to postpone choosing of default template until entity manager is available. As a side note I also noticed that JPAQuery#clone is still forgetting to tag along the chosen template (mentioned in the referenced issue).

@timowest
Copy link
Member

@timowest timowest commented Apr 17, 2013

As a side note I also noticed that JPAQuery#clone is still forgetting to tag along the chosen template (mentioned in the referenced issue).

clone takes the JPQLTemplates variant that fits best the given EntityManager

JPAQuery q = new JPAQuery(entityManager, JPAProvider.getTemplates(entityManager), getMetadata().clone());

Since clone is meant to be used for detached queries, this IMHO makes sense.

Here is the commit where this change happened 69ea056

@TuomasKiviaho
Copy link
Contributor Author

@TuomasKiviaho TuomasKiviaho commented Apr 18, 2013

Thanks for the clarification,

I didn't think the cloning issue though I guess, sorry about that. Now there's only the main issue and here's a patch for it.

diff --git src/main/java/com/mysema/query/jpa/impl/JPAQueryFactory.java src/main/java/com/mysema/query/jpa/impl/JPAQueryFactory.java
index 06b835d..e33ed05 100644
--- src/main/java/com/mysema/query/jpa/impl/JPAQueryFactory.java
+++ src/main/java/com/mysema/query/jpa/impl/JPAQueryFactory.java
@@ -34,17 +34,17 @@
     private final Provider<EntityManager> entityManager;

     public JPAQueryFactory(Provider<EntityManager> entityManager) {
-        this(JPQLTemplates.DEFAULT, entityManager);
+        this.entityManager = entityManager;
     }

     public JPAQueryFactory(JPQLTemplates templates, Provider<EntityManager> entityManager) {
-        this.entityManager = entityManager;
+        this(entityManager);
         this.templates = templates;
     }

     @Override
     public JPADeleteClause delete(EntityPath<?> path) {
-        return new JPADeleteClause(entityManager.get(), path, templates);
+        return templates == null ? new JPADeleteClause(entityManager.get(), path) : new JPADeleteClause(entityManager.get(), path, templates);
     }

     @Override
@@ -54,12 +54,12 @@

     @Override
     public JPAUpdateClause update(EntityPath<?> path) {
-        return new JPAUpdateClause(entityManager.get(), path, templates);
+        return templates == null ? new JPAUpdateClause(entityManager.get(), path) : new JPAUpdateClause(entityManager.get(), path, templates);
     }

     @Override
     public JPAQuery query() {
-        return new JPAQuery(entityManager.get(), templates);
+        return templates == null ? new JPAQuery(entityManager.get()) : new JPAQuery(entityManager.get(), templates);
     }

     @Override
@timowest
Copy link
Member

@timowest timowest commented Apr 18, 2013

Looks quite similar to this one 6436828

@TuomasKiviaho
Copy link
Contributor Author

@TuomasKiviaho TuomasKiviaho commented Apr 18, 2013

Thanks a bunch

Great Minds Think Alike, but Fools Seldom Differ

@timowest
Copy link
Member

@timowest timowest commented Apr 18, 2013

I'll close it, when it's released.

@timowest timowest reopened this Apr 18, 2013
@timowest
Copy link
Member

@timowest timowest commented May 27, 2013

Released in 3.2.0

@timowest timowest closed this May 27, 2013
@timowest timowest added this to the 3.2.0 milestone Apr 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants