@RepeatableSE(valueSE=Converts.class) @TargetSE(valueSE={METHODSE,FIELDSE,TYPESE}) @RetentionSE(valueSE=RUNTIMESE) public @interface Convert
Basic アノテーションまたは対応する XML 要素を使用する必要はありません。Convert アノテーションは、ID 属性、バージョン属性、関連属性、列挙型または時間として明示的に示されている属性の変換を指定するために使用しないでください。このような変換を指定するアプリケーションは移植できません。
Convert アノテーションは、基本属性または基本型の要素コレクションに適用できます(この場合、コンバーターはコレクションの要素に適用されます)。このような場合、attributeName 要素を指定しないでください。
Convert アノテーションは、埋め込み属性、またはキーまたは値が埋め込み型のマップコレクション属性に適用できます(この場合、コンバーターは、コレクションに含まれる埋め込み可能インスタンスの指定された属性に適用されます)。このような場合、attributeName 要素を指定する必要があります。
複数レベルの埋め込みで変換マッピングをオーバーライドするには、ドット("." )表記形式を attributeName 要素で使用して、埋め込み属性内の属性を示す必要があります。ドット表記で使用される各識別子の値は、それぞれの埋め込みフィールドまたはプロパティの名前です。
埋め込み可能クラスのインスタンスを含むマップに Convert アノテーションを適用する場合は、attributeName 要素を指定する必要があります。また、"key." または "value." を使用して、変換する属性の名前の前に接頭辞を付けて、属性の一部として指定する必要があります。マップキーまたはマップ値。
基本型のマップキーの変換を指定するために Convert アノテーションがマップに適用される場合、変換されるのがマップキーであることを指定するために、"key" を attributeName 要素の値として使用する必要があります。
Convert アノテーションは、マップされたスーパークラスを継承するエンティティクラスに適用して、継承された基本属性または埋め込み属性の変換マッピングを指定またはオーバーライドできます。
Example 1: Convert a basic attribute
@Converter
public class BooleanToIntegerConverter
implements AttributeConverter<Boolean, Integer> { ... }
@Entity
public class Employee {
@Id long id;
@Convert(converter=BooleanToIntegerConverter.class)
boolean fullTime;
...
}
Example 2: Auto-apply conversion of a basic attribute
@Converter(autoApply=true)
public class EmployeeDateConverter
implements AttributeConverter<com.acme.EmployeeDate, java.sql.Date> { ... }
@Entity
public class Employee {
@Id long id;
...
// EmployeeDateConverter is applied automatically
EmployeeDate startDate;
}
Example 3: Disable conversion in the presence of an autoapply converter
@Convert(disableConversion=true)
EmployeeDate lastReview;
Example 4: Apply a converter to an element collection of basic type
@ElementCollection
// applies to each element in the collection
@Convert(converter=NameConverter.class)
List<String> names;
Example 5: Apply a converter to an element collection that is a map or basic values.
The converter is applied to the map value.
@ElementCollection
@Convert(converter=EmployeeNameConverter.class)
Map<String, String> responsibilities;
Example 6: Apply a converter to a map key of basic type
@OneToMany
@Convert(converter=ResponsibilityCodeConverter.class,
attributeName="key")
Map<String, Employee> responsibilities;
Example 7: Apply a converter to an embeddable attribute
@Embedded
@Convert(converter=CountryConverter.class,
attributeName="country")
Address address;
Example 8: Apply a converter to a nested embeddable attribute
@Embedded
@Convert(converter=CityConverter.class,
attributeName="region.city")
Address address;
Example 9: Apply a converter to a nested attribute of an embeddable that is a map key
of an element collection
@Entity public class PropertyRecord {
...
@Convert(attributeName="key.region.city",
converter=CityConverter.class)
@ElementCollection
Map<Address, PropertyInfo> parcels;
}
Example 10: Apply a converter to an embeddable that is a map key for a relationship
@OneToMany
@Convert(attributeName="key.jobType",
converter=ResponsibilityTypeConverter.class)
Map<Responsibility, Employee> responsibilities;
Example 11: Override conversion mappings for attributes inherited from a mapped superclass
@Entity
@Converts({
@Convert(attributeName="startDate",
converter=DateConverter.class),
@Convert(attributeName="endDate",
converter=DateConverter.class)})
public class FullTimeEmployee extends GenericEmployee { ... }
| 修飾子と型 | オプションの要素と説明 |
|---|---|
StringSE | attributeNameConvert アノテーションが基本型の属性または基本型の要素コレクションにない限り、attributeName 要素を指定する必要があります。 |
ClassSE | converter 適用するコンバーターを指定します。 |
boolean | disableConversion 自動適用または継承されたコンバーターを無効にするために使用されます。 |
Copyright © 2019 Eclipse Foundation.
Use is subject to license terms.