Question

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)
Was it helpful?

Solution 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.

OTHER TIPS

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)
    .....
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top