Announcement Announcement Module
Collapse
No announcement yet.
Help with creating a custom finder Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with creating a custom finder

    Hello all,

    Can someone point me to some good reference material or a how to on how to create a custom finder? I've been cranking along with Roo, and so far so good, however my application is a bit more complex than the simple finders that come with my entity classes...I need to join multiple tables. I've seen a lot of forums on the internet talking about how this need can be satisifed with a custom finder, however I was unable to find how to create a custom finder. I think I have to use STS and "push in" an already created finder and modify it...however that's just what I've gleaned from some forums and blogs, and again I'm not really sure where to start (STS won't even start on my machine).

    Must I use STS if I'm going to create a custom finder? Can someone help point me in the right direction?

    Thanks so much,
    Pedro

  • #2
    At the moment, Roo can only generate single-entity finders, e.g. in the "Pet Clinic" sample application, you can generate "findPetsByNameEquals(String name)" and "findPetsByOwner(Owner owner)", but not "findPetsByOwnerFirstNameEquals(String firstName)". Multi-entity finders are definitely on our radar, in fact we were only talking at lunch today about how the shell commands might look.

    Anyway, the easiest way to generate a custom finder in the current release is to:
    1. Use the "finder list" and "finder add" commands to generate a built-in finder that goes some way towards what you want (or use this tip if you want to query by lots of fields).
    2. "Push" that finder into your entity class either by:
      • Using your IDE's AspectJ plugin (e.g. the one available for Eclipse, installed by default in STS), or
      • Copying-and-pasting it from the Blah_Roo_Finder.aj file into your entity class (using any text editor you like) and fixing the compile errors in that class (Roo will fix the .aj file itself next time you run the shell)
    3. Modify the pushed-in finder's JPQL query to meet your needs (which being standard JPA is outside the scope of this forum).
    Hopefully this is enough to get you started?

    Comment


    • #3
      Thanks so much for your help. After weighing my options I decided to use STS ... I hadn't been able to open STS because I had downloaded the wrong version for my JDK and Windows install (needed to get the 64 bit version). So I got STS working, and was able to refactor->push in very nicely. Once that was working I was able to get to the JPA query and work from there.

      An important downside of this is that it removes Roo from your project. I wasn't necessarily ready to quit the roo quite yet, however there are methods for re-enabling roo on your project.

      Another important downside (perhaps outside the scope of this thread) is that I wasn't able to use STS to effectively debug at runtime...the breakpoints didn't seem to line up and seemed to be stopping inconsistently...as such I decided to try to open the project in Netbeans, which was a bad mistake...it seems Netbeans has done something to my project that prevents it from running in STS now...trying to run I get java.lang.NoClassDefFoundError: org/apache/tiles/startup/BasicTilesInitializer ... so I guess what makes Roo so powerful can also be part of it's downfall--I guess I don't understand enough about Roo to understand exactly how to fix it, and I may have to scrap this project entirely. It looks like I have some internet searching to do to see why even though tiles-core-2.2.1.jar is referenced and in my dependencies in pom.xml, it is still not able to load it.

      At any rate, my original issue of how to create a custom finder was successful, even if trying to do something useful to build it out ended in disaster.

      Thanks again for pointing me in the right direction!

      Cheers,
      Pedro

      Comment


      • #4
        Originally posted by pedrop View Post
        I got STS working, and was able to refactor->push in very nicely. ... An important downside of this is that it removes Roo from your project. I wasn't necessarily ready to quit the roo quite yet, however there are methods for re-enabling roo on your project.
        You don't need to push in the whole project, just push in that one finder method. That way, Roo will keep its hands off your finder but still maintain the rest of the code that remains in your ITDs.

        Originally posted by pedrop View Post
        it seems Netbeans has done something to my project that prevents it from running in STS now
        I can't help you fix your project in NetBeans because I'm not familiar with it, but you should be able to fix your project for use with STS; as follows:
        1. Open a command/shell prompt
        2. Go to your project's root folder
        3. Run "mvn clean eclipse:clean eclipse:eclipse"; this will regenerate the Eclipse-specific .project and .classpath files that Eclipse and STS read in order to understand your project's layout, type (e.g. Java, AspectJ, etc.), dependencies, etc.
        4. Refresh your project in STS (right-click on it and choose "Refresh" from the context menu); it should now build properly (although I can't help you with the debugging side of things)
        Hope this helps,

        Andrew

        Comment


        • #5
          You should go back to the state of your project using your versioning system I use Mercurial before "finder add" and regenerate your Finder as Andrew suggests and push in only that particular Finder and adapt this according to your needs.

          I also suggest you write tests in the Roo generated java source test files to verify your structure and that your generate test stubs with Roo to get started.

          Did you see the free pdf-version of the book "Getting started with Roo"? There is also a great MEAP at Manning called Spring Roo in Action by Ken Rimple and Srini Penchikala. What you ask about is addressed there. Recommended. Part of the source code is already downloadable.

          Comment


          • #6
            Thanks guys for your replies. I was able to restore my project and all is well. My troubles now stem from my inexperience with STS/Eclipse and having to learn a new IDE (I normally use intelliJ). I've also learned to stay away completely from NetBeans. I'm hesitant to purchase Manning products as I was underwhelmed by their "Spring in Action" rev3. The "Getting started with Roo" wedding tutorial was excellent, minus the non mention of the complex/multi-entity finders.

            I think I have enough in place now to proceed on my adventure with Spring Roo. Thanks again for all your help!

            Cheers
            Pedro

            Comment

            Working...
            X