Announcement Announcement Module
No announcement yet.
Versioning of entities results in multiple entries Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Versioning of entities results in multiple entries

    I got multiple entries when adding fields to a specific table and doing updates.

    ROO version: RC3
    Database: MySQL 5.1
    mode: update

    Are there any issues for this topic already?

    Cheers Fireball

  • #2
    Would you mind pasting a Roo script that shows what steps were taken to produce an application that shows this behaviour? Am I correct in understanding the report as when you use Roo's default @RooEntity - which includes optimistic locking semantics via JPA's @Version - you end up with more than one row for that entity in your MySQL database? This is a very strange situation. Would you mind pasting in the entity's .java file so we can see what it looks like?


    • #3
      Hi Ben,

      there's nothing special with that class, just normal entity and fields commands, but ahhh no special PrimaryKey (_id will be used), perhaps this is the problem.

      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 javax.validation.constraints.NotNull;
      public class Customer {
          private String name;
          private Integer id;
          private String phone;
          public String toString() {
              return name;
      result is this:

      with duplicate foo entries.

      Hope this helps,

      P.S.: Unfortunatelly I have no roo script anymore, but I think it's clear, right?


      • #4
        I'd suggest to remove the "private Integer id" field. This is because Roo would be creating a new identifier field (probably of type Long and called "_id" given you already have "id").

        So your choices are:

        1. Remove the private Integer id field. This is the simplest option and least amount of work. Note the resulting identifier field will be of type Long, though.

        2. Add the @Id annotation to your private Integer id field, then provide a public getter/setter for the field. That way Roo will treat your id field as the identifier.

        3. Remove the private Integer id field. Modify the @RooEntity annotation to be @RooEntity(identifierType=Integer.class). That way Roo will add an Integer-based "id" field into the ITD and use it as the identifier instead.



        • #5
          Hmm ok so it is a problem with the field name. The purpose of the id field was just to have an id not a primary key. So if just the naming of the field is the problem, this should be avoided, right?

          But if Roo uses a _id field this should work anyway, right?


          • #6
            In theory it should work as Roo will treat your id field as any other entity field and nothing special. But given you're having trouble, I recommend trying one of my suggestions to see if it fixes it. You may have stumbled across a bug, perhaps in the web tier (which might be assuming the field is "id" for example).

            It one of my suggestions works, please use Roo commands to create a new entity and add an "id" field to it. Then please test to see if it still has a problem. If it does, please log a bug report at and we will dig into it for you.