Announcement Announcement Module
Collapse
No announcement yet.
Prevent Roo active record annotation from creating a @Version field Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Prevent Roo active record annotation from creating a @Version field

    After using the Roo shell and the entity jpa command to create some of the model layer of my web program, I've noticed that there is a Roo-created version instance variable that gets attached to the model classes, and this generates 'version' columns in the corresponding database tables. Is there any way to disable this behavior while still maintaining all the other Roo functionality? If I delete the version variable declaration from the [class]_Roo_Jpa_Entity.aj files, will that be sufficient? Is there a chance Roo will re-insert them at some point? The .aj files contain "DO NOT EDIT THIS FILE" comments so I'm a little hesitant.

    I can see that both the Java class field name and the database column name are configurable through arguments to the @RooJpaActiveRecord annotation. As a wild guess, I tried supplying "null" for versionField and versionColumn, and void for versionType and it (understandably) didn't compile any of those attempts.

    We've already planned the database design prior to any application code. I'm new to JPA and Java EE programming in general. I'm not sure how important this field is, and I plan to read more about JPA after I submit this post, but I'd really prefer not to have the version columns in all my database tables.

  • #2
    Hi,

    try to declare
    Code:
    private transient java.lang.Integer version;
    to your entity. Roo will remove this field from ITD and transient fields are not in database.

    Then try if persist works. I am not sure.

    Ps: If you change ITD (*.aj) roo shell will regenerate this file. So declaration same named fields or methods is way how can you edit ITDs.

    Hope it helps.

    Comment


    • #3
      I was really excited to try this because it's a clever and sensible idea, but unfortunately Roo has outsmarted us and just renamed all the columns from "version" to "version_"

      Comment


      • #4


        Ok so I looked to spring-roo/addon-jpa/src/main/java/org/springframework/roo/addon/jpa/entityJpaEntityMatadata.java line 678

        Code:
        // Quit at this stage if the user doesn't want a version field
        final String versionField = annotationValues.getVersionField();
        if ("".equals(versionField)) {
           return null;
        }
        So try to declare versionField as empty string
        Code:
        @RooJpaActiveRecord(versionField = "")
        Otherwise try to ask autor Andrew Swan.

        Comment


        • #5
          If you want to avoid the version field, just tell Roo as valerian said:

          Code:
          @RooJpaEntity(versionField = "")
          Code:
          @RooJpaActiveRecord(versionField = "")
          The Roo shell will remove the version field and all the accesses to it, from the main classes as well as the test classes (try to exit the shell and start it again if it doesn't modify the tests)

          Comment

          Working...
          X