سؤال

I am using netbeans 8, hibernate 4, mysql. I create entities with netbeans by selecting entity classes from database menu. I need optimistic lock field for my entities.I have version column on all tables in the db. How can i add @Version annotation automatically to all tables?

@Version
@Column(name="version", nullable=false)
هل كانت مفيدة؟

المحلول 2

I found solution as using replace in projects... I am selecting entities package then i search for:

 private int version;

And i replace it with:

 @Version
 private int version;

Then i click replace all for this package and i got version annotation for all of my entities.

نصائح أخرى

How about just creating a base class and having all entities extend the base class

@MappedSuperclass
public abstract class BaseEntity implements Serializable {

    @Version
    @Column(name="version", nullabe=false)
    .....
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top