Example usage for javax.persistence AttributeConverter convertToEntityAttribute

List of usage examples for javax.persistence AttributeConverter convertToEntityAttribute

Introduction

In this page you can find the example usage for javax.persistence AttributeConverter convertToEntityAttribute.

Prototype

public X convertToEntityAttribute(Y dbData);

Source Link

Document

Converts the data stored in the database column into the value to be stored in the entity attribute.

Usage

From source file:org.kuali.rice.krad.data.jpa.Filter.java

/**
 * Uses the {@link Convert} converter to first translate the {@code attributeValue} to the desired type and then
 * convert it to the database format for searching.
 *
 * @param convert the conversion annotation.
 * @param attributeName the attribute name of the field to coerce.
 * @param attributeValue the value to coerce.
 * @return the coerced value.//  w w w  .  j av a2s  .co m
 */
private static Object coerceConverterValue(Convert convert, String attributeName, String attributeValue) {
    try {
        AttributeConverter<Object, String> converter = (AttributeConverter<Object, String>) convert.converter()
                .newInstance();
        Object entityAttribute = converter.convertToEntityAttribute(attributeValue);
        return converter.convertToDatabaseColumn(entityAttribute);
    } catch (Exception e) {
        LOG.error("Could not create the converter for " + attributeName, e);
    }

    return attributeValue;
}