0

I’m new to Spring Roo and looking to build an application. I need to have combo boxes to select values into string fields – a fairly common requirement. The Spring Roo Pizza example shows this using enumerated data types enum constant, but I require the source values to be editable by an admin (ie in a table) so we can change the values in the future. Further, my preference would be to use a single table to contain all these lists for easier maintenance.

I know the SQL I want to generate the list would be something like:

Select listvals FROM listTable WHERE listtype = “status”;

Then, my dropdown box would show something like: Active, Inactive. The user would select one, and the string “Active” would be stored in the target field. And in a second example, we might use:

Select listvals FROM listTable WHERE listtype = “State”;

The second dropdown box would show something like: Alaska, California, Florida. The user would select one, and the string “Florida” would be stored in the target field.

My CORE question is how does one achieve this sort of function in Roo?

Using the Pizza Shop quick start as a sandbox I have tried defining the target fields such as:

I changed: field reference --fieldName base --type ~.domain.Base to:

field reference --fieldName base --type ~.domain.Base --referencedColumnName name

Which returned this error: @JoinColumn name is required if specifying a referencedColumnName

The initial problem is that at this point roo has yet to create the row ID columns for the db, so I don’t know the name of the join column on the Base table. But, if I wait until after I run the script with a 1:M join, the column pizza.base will be defined as an integer, and not the string that I want.

So, I ran the vanilla pizza shop roo script and interrogated the vanilla db. (Does roo generate an SQL script for db creation that I could look at?) As it turns out, roo names the row id column “id” as a BigInt. (I also note that it doesn't seem to make use of the SEQUENCE feature that postgres recommends for primary indices / row Ids.)

So now I run:

field reference --fieldName base --type ~.domain.Base --referencedColumnName name --joinColumnName id

Roo likes this!
Until I perform tests where it throws out a number of undecipherable errors in the Surefire reports.

I note that solving this problem is only step 1 to meeting my overall requrement described above. Step 2 will be to try to inject some sort of filter or where clause into the reference statement. I suspect that this has to do with the --fetch option (Roo support docs (http://docs.spring.io/autorepo/docs/spring-roo/1.2.5.RELEASE/reference/html/command-index.html#command-index-finder-commands - The fetch semantics at a JPA level; no default value)

But, I can’t find an example of this to see if I’m on the right track or to model my ‘fetch semantics’ – whatever those are. Another possibility might be to use field list to define a class containing my list of dropdown values. This has a similar modifier --fetch, but again I can’t find any examples.

I’d really appreciate some help in answering my CORE question above.

THANKS!

MaybeWeAreAllRobots
  • 1,105
  • 2
  • 9
  • 12
  • Please answer. This should be a pretty basic function: Look up a list of strings from a table, put them in a dropdown box, and store the string the user selects. And, thanks for the, er, encouragement leeor. – MaybeWeAreAllRobots Sep 28 '15 at 05:42
  • Perhaps I should just ask, in Roo how does one store a field's value instead of the the row ID for it? Is there a combination of set/reference that will accomplish this? – MaybeWeAreAllRobots Sep 30 '15 at 04:02

1 Answers1

1

Fetch parameter indicates whether the association should be lazily loaded or must be eagerly fetched (https://docs.oracle.com/javaee/6/api/javax/persistence/ManyToOne.html#fetch()).

Maybe the error of tests can be because you try to find, create, delete or update elements with related elements that not exists. Check this first of all.

You can see an example of application created with gvNIX (distribution of Spring Roo) that contains relationships between some entities on https://github.com/DISID/gvnix-samples/blob/master/quickstart-app/quickstart.roo

Manuel
  • 166
  • 1
  • 7
  • Gracias Manuel. I'm not that advanced to understand lazy/eager yet, but I understand that --fetch is not useful to me for my opbjective. I have been using gvNIX (good stuff!). I don't want to build a relationship with a FKey at all - I just want a string value from another table. It seems very similar to a 1:m relationship so I was hoping that roo could provide it. – MaybeWeAreAllRobots Sep 30 '15 at 05:56