Announcement Announcement Module
No announcement yet.
versionField Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • versionField

    Is this required for RooEntities. The doc does not say it s mandatory.
    I would like to know if I need this for Roo 1.1.1



  • #2
    The use of JPA @Version is optional. It indicates that the table contains versioned data which can be very helpful if you plan to use long transactions and have the possibility of dirty reads. So I would recommend for you to use it but it is an optional feature of JPA.


    • #3
      DBRE won't let it be optional

      Roo is forcing a versionField setting in the DBRE addon. If a table dosn't already have a version field, it creates a blank one (versionField="") in createNewManagedEntityFromTable. If you remove it from the generated class file, DBRE adds it back next time updateOrDeleteManagedEntity gets called. The documentation sayys that you can incrementally update the database and run DBRE repeatedly, but that will result in the versionField attribute getting added back every time.

      It kind of looks like a bug to me. In updateOrDeleteManagedEntity:

      get existing version field attribute
      if the version field attribute is not null:
      get version field value
      if the current table has a column called "version" AND (the version field value is blank OR the version field value equals "version", then remove the versionField attribute.

      if the version field attribute is null:
      if the current table has a column called "version", remove the version field
      if the current table doesn't have a column called "version", add version field attribute with a version value of "".

      So, I'm really confused by this logic. If I don't have a version field in my table, I'm always going to get a versionField attribute added to my classes. If there's a version field in the table, but no versionField attribute, then the code will try to delete a non-existent versionField attribute.


      • #4
        If there is no version field in the table the versionField = "" attribute will ensure a version field is not created in the entity ITD. If you don't have this attribute, then a field called "version" will be created and annotated with @Version. You need to leave this in or else create a version field in the table.