We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeConverter는 주로 다음과 같은 상황에서 사용된다.
public interface AttributeConverter<X,Y> { public Y convertToDatabaseColumn (X attribute); public X convertToEntityAttribute (Y dbData); }
public enum DirectoryType { DEFAULT, CUSTOM, UNKNOWN } @Converter public class DirectoryTypeConverter implements AttributeConverter<DirectoryType, String> { @Override public String convertToDatabaseColumn(DirectoryType attribute) { return attribute.name(); } @Override public DirectoryType convertToEntityAttribute(String dbData) { return Arrays.stream(DirectoryType.values()).filter(constraintSet -> constraintSet.name().equals(dbData)) .findAny().orElse(DirectoryType.UNKNOWN); } } @Entity public class ServiceDirectory { @Id @Column @GeneratedValue(strategy = GenerationType.IDENTITY) private Long no; @Convert(converter = DirectoryTypeConverter.class) private DirectoryType directoryType; }
public class Money { private Double value; private String currency; public Money(Double value, String currency) { this.value = value; this.currency = currency; } public Double getValue() { return value; } public void setValue(Double value) { this.value = value; } public String getCurrency() { return currency; } public void setCurrency(String currency) { this.currency = currency; } @Override public String toString() { return value.toString() + currency; } }
@Converter(autoApply = true) public class MoneyConverter implements AttributeConverter<Money, String> { @Override public String convertToDatabaseColumn(Money attribute) { if (attribute == null) { return null; } return attribute.toString(); } @Override public Money convertToEntityAttribute(String dbData) { if (dbData == null) { return null; } else { String value = dbData.substring(0, dbData.length() - 3); String currency = dbData.substring(dbData.length() - 3); return new Money(Double.valueOf(value), currency); } } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
AttributeConverter
AttributeConverter는 주로 다음과 같은 상황에서 사용된다.
JPA가 지원하지 않는 타입을 매핑
두 개 이상의 속성을 갖는 밸류 타입을 한 개 컬럼에 매핑
The text was updated successfully, but these errors were encountered: