Announcement Announcement Module
Collapse
No announcement yet.
Spring Roo DBRE Primary Key Insert / Update (asked on stackoverflow, needs answer) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Roo DBRE Primary Key Insert / Update (asked on stackoverflow, needs answer)

    The following question, which I also have, is on stackoverflow

    I am creating an application with Spring Roo. When I do a reverse engineer on a database table everything looks great but there are no fields for the primary keys, which are in the database. These are not auto incrementing but rather need to be filled manually or are drive off another table. When I launch my spring roo application I can create or view the tables and their fields but I can'r see primary key anywhere to view or update. Any advice on how to accomplish this?
    the stackoverflow link

  • #2
    Anyone have an answer?

    Comment


    • #3
      What do you mean there are no fields? Are there xxx_Roo_Identififer ITDs present ?

      Comment


      • #4
        For example I have a Documenttype_Roo_Jpa_Entity.aj file at end which was created by DBRE

        Since the Id is a String, I want to supply it manually in the Web interface. How can I tell Roo/Spring that it should include an input field in the generated web layer such that I can supply it manually? I assume since this is the Id/PK Roo thinks that this is generated automatically and therefore does not need to be editable on the web layer, however in my case (and the persons on stackoverflow) we need to provide it manually, and need it exposed and editable in the web layer.

        Please note that the Entity.aj file contains this Id field but not in the DbManaged.aj file. (I am mentioning in case this matters.)

        Thanks in advance.


        privileged aspect Documenttype_Roo_Jpa_Entity {

        declare @type: Documenttype: @Entity;

        declare @type: Documenttype: @Table(name = "documenttype");

        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name = "documentTypeCd", columnDefinition = "CHAR", length = 4)
        private String Documenttype.documentTypeCd;

        public String Documenttype.getDocumentTypeCd() {
        return this.documentTypeCd;
        }

        public void Documenttype.setDocumentTypeCd(String id) {
        this.documentTypeCd = id;
        }

        }
        Last edited by melutovich; Nov 21st, 2012, 06:22 AM.

        Comment


        • #5
          The mvc latyer does not support the editing of primary keys unless the id is a composite key, in which you must enter values for.

          Comment


          • #6
            Thanks. Next second approach question:

            I've seen some where that I could add a @PrePersist method to set the PK/id, however that involved editing the Enity.aj file, which can get overridden, when I added it into the general .java file, it was not recognized, where should I place the @PrePersist method so that it is recognized and not overridden?

            Comment


            • #7
              Hi melutovich,
              Were you able to resolve the update issue? I have similar problem.

              Thanks in advance.

              Rgds,
              Kiru.

              Comment


              • #8
                Quick answer, I was able to generate a random string using the UUID and set it with a method in the .aj file with @PrePersist; however I had to do with when roo is not running so that the method isn't overridden. Since in the end of the day we didn't need this, I didn't push on it further. If on the latest version of ROO this still occurs I would suggest you open a JIRA issue. If you need more details let me know. Sorry it took a while for me to response I needed to reset my id and had problems with my filter.

                Comment


                • #9
                  You might also want to look at https://jira.springsource.org/browse/ROO-1040

                  Comment


                  • #10
                    I wouldn't edit the ITD .aj file as it will be overwritten as you say. Why don't you simply push-in the identifier ITD and add your @PrePersist method in the .java file?

                    Comment


                    • #11
                      Alan,

                      1) In general I think that pushing in from the ITD should be done as a last resort, it becomes a lock in once done. But I hear you in this instance.
                      2)It has been a while since I've done this, but if I remember correctly the way I wanted to approach this was to create a NEW method in the java file and add the @PrePersist; however for some reason that did not work. If I remember correctly having the new method within the ITD .aj of ROO did work. I didn't pursue the reason why in the java file it did not work.

                      Comment

                      Working...
                      X