Example usage for org.hibernate.mapping RootClass setOptimisticLockMode

List of usage examples for org.hibernate.mapping RootClass setOptimisticLockMode

Introduction

In this page you can find the example usage for org.hibernate.mapping RootClass setOptimisticLockMode.

Prototype

@Deprecated
public void setOptimisticLockMode(int optimisticLockMode) 

Source Link

Usage

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

protected void bindVersion(GrailsDomainClassProperty version, RootClass entity, Mappings mappings,
        String sessionFactoryBeanName) {

    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.getDomainClass().getClazz().getName()
                    + "; must be one of [int, Integer, long, Long, Timestamp, Date]. Not mapping the version.");
            return;
        }//w w  w  . ja v a2s .co m
    } else {
        val.setTypeName("version".equals(version.getName()) ? "integer" : "timestamp");
    }
    Property prop = new Property();
    prop.setValue(val);

    bindProperty(version, prop, mappings);
    val.setNullValue("undefined");
    entity.setVersion(prop);
    entity.setOptimisticLockMode(0); // 0 is to use version column
    entity.addProperty(prop);
}

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

License:Apache License

protected void bindVersion(PersistentProperty version, RootClass entity, Mappings 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;
            }//  w  w w  .j  a  v  a  2  s  . c o m
        } else {
            val.setTypeName("version".equals(version.getName()) ? "integer" : "timestamp");
        }
        Property prop = new Property();
        prop.setValue(val);

        bindProperty(version, prop, mappings);
        val.setNullValue("undefined");
        entity.setVersion(prop);
        entity.setOptimisticLockMode(0); // 0 is to use version column
        entity.addProperty(prop);
    }
}