Announcement Announcement Module
Collapse
No announcement yet.
How do I add a field to an existing class Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I add a field to an existing class

    Hi All:
    I am very new to roo. Trying to write a sample. When I try adding a field to an exiting domain class roo complains . I have tried the following without any luck.

    A)
    field date doj --type java.util.Date
    java.lang.IllegalArgumentException: Java source code details unavailable for type SRC_MAIN_JAVA/com.stragure.hrms.domain.Employee
    ...
    ...
    ..

    B) field date doj --type java.util.Date ~.domain.Employee
    You cannot add more than one default option ('~.domain.Employee') in a single command

    c) field date --fieldName doj --type java.util.Date --class ~.domain.Employee
    Java source code details unavailable for type SRC_MAIN_JAVA/com.stragure.hrms.domain.Employee
    java.lang.IllegalArgumentException: Java source code details unavailable for type SRC_MAIN_JAVA/com.stragure.hrms.domain.Employee

    I am struggling to find the rite syntax maybe but tab hints lead to commands shown in (c) above but does not work and I am not sure what ava source code details unavailable for type SRC_MAIN_JAVA means...

    Regards,
    rohit

  • #2
    Hi Rohit,

    It appears that the Employee type does not exist yet.

    In order to add a field you need to have an existing type present. So in your example you would issue two commands:

    Code:
    entity --name ~.domain.Employee
    field date --type java.util.Date --fieldName doj
    The second command will add the doj field to the Employee type. In case you want to add that field to another (already existing) type you would need to use the --class attribute:

    Code:
    field date --type java.util.Date --fieldName doj --class ~.domain.MyOtherType
    The trick is to use the tab key as much as possible when typing your commands. That will reveal which attributes are available on commands and which attributes are mandatory.

    So in short, when Roo tells you that "Java source code details unavailable for type ..." that means you will probably need to create that type first using the 'entity' command or the 'class' command.

    HTH,

    Stefan

    Comment


    • #3
      Hi Stefan:
      thanks for your reply. I do have the entity Employee. It looks like this -

      package com.stragure.hrms.domain;

      import javax.persistence.Entity;
      import org.springframework.roo.addon.javabean.RooJavaBean ;
      import org.springframework.roo.addon.tostring.RooToString ;
      import org.springframework.roo.addon.entity.RooEntity;
      import com.stragure.hrms.domain.PhoneNumber;

      @Entity
      @RooJavaBean
      @RooToString
      @RooEntity
      public class Employee {

      private String id;

      private String name;

      private String sex;

      private String educational_q;

      private String address;

      private String email;

      private PhoneNumber java.lang.Integer;
      }

      All I want is to add another field to it so far no success. On the other hand I could create other entities and add fields to it but for some strange reason not to Employee.

      Regards,
      Rohit

      Comment


      • #4
        Hi Rohit,

        This sounds more like a bug then. Can you enable 'development mode' before issuing your field command? Then open a new bug ticket here http://jira.springframework.org/browse/ROO and provide the complete stack trace along with all commands you issued so far.

        Ideally you would also attach the sources of your project so we can test with that. There is a 'backup' command which creates a zip file of your project conveniently.

        Can you also include details about your environment into the ticket (OS, Java version, maven version, Roo version, etc)?

        Cheers,
        Stefan

        Comment


        • #5
          Hi Stefan:
          I did that http://jira.springframework.org/browse/ROO-376

          'backup' is not working at the moment.See the same jira issue.
          I can anyway zip the project but where shall I upload ? couldn't find attach/upload option in jira

          Also - apologies I am new to many things (jira, roo etc) so please bear with me.

          REgards,
          Rohit
          Last edited by rohitpant; Nov 11th, 2009, 09:34 PM. Reason: typo

          Comment


          • #6
            Hi Rohit,

            Thanks for opening this ticket. I see you are using Roo RC2. Please note that we have released RC3 in the meantime. Can you please try this, just to make sure that this issue has not been fixed in the meantime. We closed well over 70 tickets for RC3.

            Also, it would help if you could provide the exact commands you issued in the Jira ticket as well as the stack trace. Attachments are available at the left hand side in Jira: "Attach file to this issue".

            Thanks,
            Stefan

            Comment


            • #7
              I am now on RC3. soon will try the same sequence which led to an error in RC2 and let you know.

              thanks again !

              Comment

              Working...
              X