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
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
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?
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.
result is this:Code: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; @Entity @RooJavaBean @RooEntity public class Customer { @NotNull private String name; @NotNull private Integer id; private String phone; public String toString() { return name; } }
with duplicate foo entries.Code:_id,version,id,name,phone 1,0,1,foo, 2,0,1,foo,123-0 3,0,2,foo2,123-60 4,0,1,foo,123
Hope this helps,
Fireball
P.S.: Unfortunatelly I have no roo script anymore, but I think it's clear, right?
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.
HTH
Ben
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?
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 http://jira.springsource.org/browse/ROO and we will dig into it for you.