Example usage for javax.persistence.metamodel EntityType hasVersionAttribute

List of usage examples for javax.persistence.metamodel EntityType hasVersionAttribute

Introduction

In this page you can find the example usage for javax.persistence.metamodel EntityType hasVersionAttribute.

Prototype

boolean hasVersionAttribute();

Source Link

Document

Whether the identifiable type has a version attribute.

Usage

From source file:org.querybyexample.jpa.GenericRepository.java

/**
 * Return the optimistic version value, if any.
 *///from   w  w  w  .  ja  va 2  s  . c o  m
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public Comparable<Object> getVersion(E entity) {
    EntityType<E> entityType = entityManager.getMetamodel().entity(type);
    if (!entityType.hasVersionAttribute()) {
        return null;
    }
    return (Comparable<Object>) JpaUtil.getValue(entity, getVersionAttribute(entityType));
}