Announcement Announcement Module
Collapse
No announcement yet.
Using QueryDSL in Custom Repository Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using QueryDSL in Custom Repository

    What is the best way to use QueryDSL in Custom Repository?

    Thanks

  • #2
    Both MongoDB and JPA modules have a QuerydslRepositorySupport base class that you can extend from to get easy access to Querydsl API.

    Comment


    • #3
      Thanks Oliver.

      I guess there should be a method in the QuerydslRepositorySupport to access MongoOperations.

      Comment


      • #4
        Why? You can simply inject it into your class if needed.

        Comment


        • #5
          I have to inject it anyway as QuerydslRepositorySupport doesn't have a no argument constructor, it has a constructor which takes MongoOperations. So inspite of passing it to QuerydslRepositorySupport, there is no way of getting it back. I have to maintain a local reference in my custom repository class.

          Comment


          • #6
            Right, that's the way it's supposed to work. If your class needs it for the implementation, keep it with your class. You shouldn't assume the superclass is keeping a reference to the constructor parameter as it might just use it inside the constructor.

            Comment


            • #7
              Right, I shouldn't make that assumption. But it is a support class like *DaoSupport classes in Spring. So, thought it would make sense to have getter for the mongoOperation( like they do for the template classes) so that the extension is clean.

              Comment


              • #8
                How is that "clean"? The purpose of the DaoSupport classes is exposing resources to you (which I personally think is a bad thing). I'd argue it's clean to keep dependencies you need locally and not rely on a superclass exposing internals. See this discussion [0] for details.

                [0] https://gist.github.com/3706123

                Comment

                Working...
                X