google Analytics

Sunday, August 29, 2010

Versioning without version numbers or timestamps Hibernate

Versioning without version numbers or timestamps in Hibernate
=============================================================

=============================================================
Application don't have version or timestamp columns, Hibernate can still perform automatic versioning, but only for objects that are retrieved and modified in the same persistence context (that is, the same Session). If you need optimistic locking for conversations implemented with detached objects, you must use a version number or timestamp that is transported with the detached object.
=============================================================

=============================================================
This alternative implementation of versioning checks the current database state against the unmodified values of persistent properties at the time the object was retrieved (or the last time the persistence context was flushed). You may enable this functionality by setting the optimistic-lock attribute on the class mapping:

<class name="Book" table="Book" optimistic-lock="all">
    <id .../>
    ...
</class>

=============================================================

=============================================================


Versioning with Java Persistence or JPA
 To enable automatic versioning for a particular entity, you need to add a version property or field:

@Entity
public class BOOK{
    ...
    @Version
    @Column(name = "VERSION")
    private int version;
    ...
}

======================================================================

=============================================================

=============================================================


Versoning Example In Hibernate
http://opensourceframework.blogspot.com/2010/07/hibernate-vesioning-example.html

No comments:

Post a Comment