Results 1 to 3 of 3

Thread: Problem with custom finders

  1. #1
    Join Date
    Feb 2012
    Location
    Russia, Siberia
    Posts
    8

    Default Problem with custom finders

    I have a small problem.

    I create own finder with simple name �findForMe�. I can`t create this finder using Roo Shell, for some reason. I update stroke @RooEntity(finders = { " findForMe�}) in entity class Myclass.Java; and add own finder in finder_class Myclass_Roo_finder.aj. After that, when running �perform package� Finder disappears from Myclass_Roo_finder.aj. What I am doing wrong?

    P.S. Sorry for my bad English.

    Truly yours, Nafanya.

  2. #2
    Join Date
    May 2006
    Location
    Madrid
    Posts
    382

    Default

    When I have to make a custom finder, I follow these steps:

    1.- Create a finder with the Roo command.

    Something like findMyEntityByValueEquals. With that a _Roo_Finder aspectJ is created, and the @RooJpaActiveRecord annotation modified with the appropriate finders atribute (for instance finders = { "findMyEntityByValueEquals" })

    2.- I copy the finder method to the Java Entity and then I modify it (including the signature, of course)

    So try to remove findForMe from the annotation (because you're telling Roo to manage this finder, so Roo tries to create/delete or whatever it considers appropriate)

    Code:
    @RooJpaActiveRecord(...)
    public class MyEntity {
    
        public static TypedQuery<MyEntity> findForMe(String me) {
            if (me== null || me.length() == 0) throw new IllegalArgumentException("The meargument is required for finding MyEntities");
            EntityManager em = MyEntity.entityManager();
    //Or whatever custom JPA-QL query  (not plain SQL query)
            TypedQuery<MyEntity> q = em.createQuery("SELECT o FROM MyEntity AS o WHERE o.me = :me", MyEntity.class);
            q.setParameter("me", me);
            return q;
        }
    
    
    }
    3.- Add tests to the MyEntityIntegrationTest

  3. #3
    Join Date
    Aug 2009
    Location
    Montréal
    Posts
    23

    Default

    don't add your custom code the aspects files because they managed by roo.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •