001/* 002 * Copyright (c) 2008, 2009, 2011 Oracle, Inc. All rights reserved. 003 * 004 * This program and the accompanying materials are made available under the 005 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 006 * which accompanies this distribution. The Eclipse Public License is available 007 * at http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License 008 * is available at http://www.eclipse.org/org/documents/edl-v10.php. 009 */ 010package javax.persistence; 011 012/** 013 * A class that implements this interface can be used to convert 014 * entity attribute state into database column representation 015 * and back again. 016 * Note that the X and Y types may be the same Java type. 017 * 018 * @param X the type of the entity attribute 019 * @param Y the type of the database column 020 * @since Java Persistence 2.1 021 */ 022public interface AttributeConverter<X, Y> { 023 /** 024 * Converts the value stored in the entity attribute into the 025 * data representation to be stored in the database. 026 * 027 * @param attribute the entity attribute value to be converted 028 * @return the converted data to be stored in the database column 029 */ 030 public Y convertToDatabaseColumn(X attribute); 031 032 /** 033 * Converts the data stored in the database column into the 034 * value to be stored in the entity attribute. 035 * Note that it is the responsibility of the converter writer to 036 * specify the correct dbData type for the corresponding column 037 * for use by the JDBC driver: i.e., persistence providers are 038 * not expected to do such type conversion. 039 * 040 * @param dbData the data from the database column to be converted 041 * @return the converted value to be stored in the entity attribute 042 */ 043 public X convertToEntityAttribute(Y dbData); 044}