Spring Roo
  1. Spring Roo
  2. ROO-2032

Allow nullable finder parameters for nullable fields

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.1.1.RELEASE
    • Fix Version/s: None
    • Component/s: DYNAMIC FINDERS
    • Labels:
      None

      Description

      A typical dynamic finder starts by checking if all input variables are NULL, and then throwing an exception if they are. However, null can be a perfectly valid argument. Consider the following

      CREATE TABLE Node (
      id int not null auto_increment,
      parentId int,
      name varchar(50),
      primary key(id),
      foreign key parentId refrences Node(id)
      );

      Here you can have many trees:
      (1,NULL,'A'), (2,1,'A1'), (3,1,'A2'), (4,2,'A1.1'),
      (5,NULL,'B'), (6,5,'B1'), (7,5,'B2')

      Now if I want to make a finder which finds a collection of nodes on a level, and I want to use it to find all the roots, findNodesByParentId(null) is a perfectly valid call, just as valid as doing findNodesByParentId(Node.read(1))

      I suggest therefore that the dynamic finder creation checks if NULL is a valid argument for the entity before adding the constraint on the method that it must have a value

      Cheers

      Nik

        Activity

        Hide
        Stefan Schmidt added a comment -

        Nik, this has come up a few times already (ROO-1804, ROO-1658). Not sure if your suggestions add too much given Roo supports finders which allow searches for null fields: findVisitsByDescriptionIsNull ...

        Show
        Stefan Schmidt added a comment - Nik, this has come up a few times already ( ROO-1804 , ROO-1658 ). Not sure if your suggestions add too much given Roo supports finders which allow searches for null fields: findVisitsByDescriptionIsNull ...
        Hide
        Andrew Swan added a comment -

        @Stefan: this is more about allowing a given field to be null in a search, rather than hardcoding that field to be null (or not null). To continue Niklas' example, he would like a single finder to be able to search for nodes with a given parent, including no parent at all.

        Show
        Andrew Swan added a comment - @Stefan: this is more about allowing a given field to be null in a search, rather than hardcoding that field to be null (or not null). To continue Niklas' example, he would like a single finder to be able to search for nodes with a given parent, including no parent at all.
        Hide
        Niklas Saers added a comment -

        Thanks Andrew, that's indeed what I meant

        Show
        Niklas Saers added a comment - Thanks Andrew, that's indeed what I meant

          People

          • Assignee:
            Unassigned
            Reporter:
            Niklas Saers
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: