Announcement Announcement Module
Collapse
No announcement yet.
How do you add a fiield of type java.util.HashMap to a Roo Entity? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do you add a fiield of type java.util.HashMap to a Roo Entity?

    Hello,

    I would like to create an abstract entity called Attachment to model an e-mail attachment, and derive two entities from it, respectively called Excel and PDF. Excel entities will contain data stored in Excel sheets and PDF entities data stored in PDF files.

    The Excel entity will contain an attribute of type HashMap. Its keys and values will contain respectively the data labels and data values respectively; for example,

    net margin -> A12
    net profit -> B23
    number of employees -> A33

    The PDF entity will also contain an attribute of type HashMap. Its keys and values will contain respectively the data labels and the label texts next to which the corresponding values are likely to be found. For instance,

    net margin -> Net Margin
    net profit -> Net Profif
    number of employees -> Employees

    assuming that the PDF, converted to text, contains the following data:

    Net Margin : 123,000 euros
    Net Profit : 20,000 euros
    Employees : 12




    How do I create an entity field of type "HashMap" in Roo?

    I have tried typing the following command on the Roo Command Line:


    entity jpa --class ~.model.Excel --extends ~.model.Attachment --testAutomatically
    field other --fieldName labelToCellMap --type java.util.HashMap<String,String>

    but to no avail because of the "<String,String>" part



    I have also tried typing

    entity jpa --class ~.model.Excel --extends ~.model.Attachment --testAutomatically
    field other --fieldName labelToCellMap --type java.util.HashMap


    but to no avail either when I later tried to compile the code with Maven:

    "Building xxxx SNAPSHOT

    [ERROR] HashMap cannot be resolved to a type"


    I could create a Roo field of type "set" containing a collection of class instances each with two attributes, "key" and "value", eg, but this seems inefficient.

    Any suggestions would be greatly welcome.

    Many thanks.

    Philroc

  • #2
    I suggest you add the field directly to the Entity's source file instead of using Roo shell commands. If you leave the Roo shell running, Roo will generate the *_Roo_*.aj files automatically.

    Comment

    Working...
    X