Example usage for javax.persistence.metamodel SingularAttribute isVersion

List of usage examples for javax.persistence.metamodel SingularAttribute isVersion

Introduction

In this page you can find the example usage for javax.persistence.metamodel SingularAttribute isVersion.

Prototype

boolean isVersion();

Source Link

Document

Is the attribute a version attribute.

Usage

From source file:cz.datalite.dao.support.JpaMetamodelEntityInformation.java

/**
 * Returns the version attribute of the given {@link javax.persistence.metamodel.ManagedType} or {@literal null} if none available.
 * /*from   w w w  .ja va 2  s.c  o m*/
 * @param type must not be {@literal null}.
 * @return
 */
private static <T> SingularAttribute<? super T, ?> findVersionAttribute(ManagedType<T> type) {

    Set<SingularAttribute<? super T, ?>> attributes = type.getSingularAttributes();

    for (SingularAttribute<? super T, ?> attribute : attributes) {
        if (attribute.isVersion()) {
            return attribute;
        }
    }

    return null;
}

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

/**
 * _HACK_ too bad that JPA does not provide this entityType.getVersion();
 *
 * @see/* www . j  ava 2s  . c  om*/
 * http://stackoverflow.com/questions/13265094/generic-way-to-get-jpa-entity-version
 */
private SingularAttribute<? super E, ?> getVersionAttribute(EntityType<E> entityType) {
    for (SingularAttribute<? super E, ?> sa : entityType.getSingularAttributes()) {
        if (sa.isVersion()) {
            return sa;
        }
    }
    return null;
}