Results 1 to 2 of 2

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

Hybrid View

  1. #1
    Join Date
    Dec 2011
    Location
    Paris, France
    Posts
    58

    Default 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. #2
    Join Date
    Jun 2005
    Location
    São Paulo, Brasil
    Posts
    86

    Default

    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.
    Simplicity is prerequisite for reliability. — Edsger W. Dijkstra

Posting Permissions

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