QueryDSL and Play Framework

泪湿孤枕 提交于 2019-12-09 00:18:40

问题


I'm using QueryDSL with JPA2 for some time, and it's the most powerful combination for ORM I know. JPA Criteria API is a disaster. With QueryDSL I've forgotten about JPQL too.

I'd like to use QueryDSL with Play! Everything looks very good in Play except those inline parts of JPQL as strings. It reminds me of CakePHP...

I'd like to have refactoring-proof querying language in Play (and some other things :) ).

QueryDSL usage would be straightforward. It needs EntityManager only. But QueryDSL has this APT class generator (just like the one from Hibernate for citeria API).

Does anyone managed to get this class generator work with Play? Is it possible to recreate and hot reload those classes?


回答1:


I think the experience of Project Lombok with annotation processing in the Play framework will be helpful to you. It is easy to setup APT processing, but very specific. Look at the play-lombok module. Don't ignore the commands.py file and change the org.eclipse.jdt.core-3.6.0.jar reference to match the version used in your version of Play.

I use Querydsl in the Play framework for all my recent projects. I do not use JPA, however. I use my own object models with Querydsl instead of ORM to get a good fit depending on the situation. I haven't had a need for APT with Querydsl.

I have not created any tight integration between Play and Querydsl, but I just use a bit of boilerplate in each controller method. Some day I'll write a proper plugin.




回答2:


I'm running play with querydsl using eclipse. (see http://blog.mysema.com/2010/10/using-querydsl-in-eclipse.html)

As generated source dir i used app/ which means that the Q classes will be generated in the same dir as the model classes which is not optimal but works.

Added these lines to the dependencies.yml

    - com.mysema.querydsl -> querydsl-jpa 2.2.3
    - com.mysema.querydsl -> querydsl-apt 2.2.3
    - log4j -> log4j 1.2.16
    - javassist -> javassist 3.12.1.GA

repositories:
    - queryDSL:
        type: iBiblio
        root: "http://source.mysema.com/maven2/releases/"
        contains:
            - com.mysema -> *           

Then use play dependencies --sync and play eclipsify and reopen the project in eclipse and it should work




回答3:


I have no experience with Play, but I know that the following managed to use Querydsl SQL with the Play framework : http://twitter.com/#!/rrmckinley

He might be able to help you. I am not aware of any other integration of Querydsl with Play.




回答4:


You could check the existing modules that change the Database adaptor (like this one for Mongo) and do something similar to link QueryDSL. Play hot-reloading should be available to it if it's a module.



来源:https://stackoverflow.com/questions/7490384/querydsl-and-play-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!