I don't know why I create new entities with roo command, it always has a filed name version.
What's the benefit of version field?
If I don't want it, how to write the roo command which doesn't generate version file in entity.
The field is annoteted with @javax.persistence.Version This is used by the Entity manager to create optimistic locking.
Let's take this scenario: There is a CD list app.
The user can open the form with the CD data and may modify it. You cannot lock the record in the database and wait wether the user wants to modify the record (e.g. with SELECT ... FOR UPDATE) since it takes too long (from the database's perspective). Most probably the connection closes after reading the data and returned to the pool.
Instead when you save the record the Entity manager checks the version field in the database if it's the same that you sent. If it is, then you can safely save your changes and increases the version by 1. If someone modified the record while you were editing it in your screen, then the version szored in the database is higher then yours, you cannot save the data, because the other person already did it. This is actually locking (you cannot save if someone else did) and opcimistic, because it only "locks" when there is a modification which isn't the case in most of the time and it does not use the database when it doesn't have to.