- Type Parameters:
T- entity class of the static metamodel.
- All Known Subinterfaces:
BasicAttribute<T,,V> ComparableAttribute<T,,V> NavigableAttribute<T,,U> NumericAttribute<T,,N> SortableAttribute<T>,TemporalAttribute<T,,V> TextAttribute<T>
- All Known Implementing Classes:
AttributeRecord,SortableAttributeRecord,TextAttributeRecord
public interface Attribute<T>
Supertype for StaticMetamodel fields representing entity
attributes.
The following subtypes are provided:
TextAttributefor entity attributes that represent text, typically of typeString.NumericAttributefor entity attributes that represent numeric values, such asint,Long, andBigDecimal.TemporalAttributefor entity attributes that represent temporal values, such asLocalDateTimeandInstant.ComparableAttributefor entity attributes that represent other sortable and comparable values, such asbooleanand enumerations.SortableAttributefor entity types that are sortable, but incapable of order-based comparison. Generally this subtype is unused but is applicable for databases that allow sorting on attributes of typebyte[].NavigableAttributefor entity attributes that have attributes of their own. This is used for embeddables and associations to other entities.BasicAttributefor other types of entity attributes, such as collections, embeddables, and other relation attributes.
To represent an entity, a static metamodel class defines a field
corresponding to each entity attribute. The type of the field should be the
most precise subtype of Attribute that describes the entity
attribute type.
For example, given the following entity class,
@Entity
public class Car {
@Id
public String vin;
public Color color;
public double discountRate;
public int firstModelYear;
public LocalDate listed;
public String make;
public String model;
public int price;
public int year;
}
public enum Color { BLACK, BLUE, GRAY, RED, WHITE }
The static metamodel class (typically generated from the entity class) would be,
@StaticMetamodel
public interface _Car {
String COLOR = "color";
String DISCOUNTRATE = "discountRate";
String FIRSTMODELYEAR = "firstModelYear";
String LISTED = "listed";
String MAKE = "make";
String MODEL = "model";
String PRICE = "price";
String VIN = "vin";
String YEAR = "year";
ComparableAttribute<Car,Color> color = ComparableAttribute.of(
Car.class, COLOR, Color.class);
NumericAttribute<Car,Double> discountRate = NumericAttribute.of(
Car.class, DISCOUNTRATE, double.class);
NumericAttribute<Car,Integer> firstModelYear = NumericAttribute.of(
Car.class, FIRSTMODELYEAR, int.class);
TemporalAttribute<Car,LocalDate> listed = TemporalAttribute.of(
Car.class, LISTED, LocalDate.class);
TextAttribute<Car> make = TextAttribute.of(
Car.class, MAKE);
TextAttribute<Car> model = TextAttribute.of(
Car.class, MODEL);
NumericAttribute<Car,Integer> price = NumericAttribute.of(
Car.class, PRICE, int.class);
TextAttribute<Car> vin = TextAttribute.of(
Car.class, VIN);
NumericAttribute<Car,Integer> year = NumericAttribute.of(
Car.class, YEAR, int.class);
}
-
Method Details
-
name
String name()Obtain the entity attribute name, suitable for use wherever the specification requires an entity attribute name. For example, as the parameter toSort.asc(String).- Returns:
- the entity attribute name.
-
declaringType
Obtain the Java class which declares this entity attribute.- Returns:
- the declaring class
- Throws:
UnsupportedOperationException- if the declaring type is not known.- Since:
- 1.1
- API Note:
- This is only guaranteed to be known if a static
ofmethod, such asBasicAttribute.of(Class, String, Class), was used to obtain the instance.
-
attributeType
Obtain the Java class of the entity attribute.- Returns:
- the type of the entity attribute.
- Throws:
UnsupportedOperationException- if the entity attribute type is not known.- Since:
- 1.1
- API Note:
- This is only guaranteed to be known if a static
ofmethod, such asBasicAttribute.of(Class, String, Class), was used to obtain the instance.
-