Example usage for org.hibernate.engine OptimisticLockStyle VERSION

List of usage examples for org.hibernate.engine OptimisticLockStyle VERSION

Introduction

In this page you can find the example usage for org.hibernate.engine OptimisticLockStyle VERSION.

Prototype

OptimisticLockStyle VERSION

To view the source code for org.hibernate.engine OptimisticLockStyle VERSION.

Click Source Link

Document

use a dedicated version column

Usage

From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

protected void bindVersion(PersistentProperty version, RootClass entity, InFlightMetadataCollector mappings,
        String sessionFactoryBeanName) {

    if (version != null) {

        SimpleValue val = new SimpleValue(mappings, entity.getTable());

        bindSimpleValue(version, null, val, EMPTY_PATH, mappings, sessionFactoryBeanName);

        if (val.isTypeSpecified()) {
            if (!(val.getType() instanceof IntegerType || val.getType() instanceof LongType
                    || val.getType() instanceof TimestampType)) {
                LOG.warn("Invalid version class specified in " + version.getOwner().getName()
                        + "; must be one of [int, Integer, long, Long, Timestamp, Date]. Not mapping the version.");
                return;
            }//from   www.  j  a va 2  s.  co  m
        } else {
            val.setTypeName("version".equals(version.getName()) ? "integer" : "timestamp");
        }
        Property prop = new Property();
        prop.setValue(val);
        bindProperty(version, prop, mappings);
        prop.setLazy(false);
        val.setNullValue("undefined");
        entity.setVersion(prop);
        entity.setOptimisticLockStyle(OptimisticLockStyle.VERSION);
        entity.addProperty(prop);
    }
}