jakarta.persistence.Basic
- Implemented Interfaces:
Annotation
- Target:
- Method, Field
The Basic annotation may be applied to a property or instance variable whose type is any one of the following:
- a Java primitive type, or wrapper of a primitive type,
String,BigIntegerorBigDecimal,LocalDate,LocalTime,LocalDateTime,OffsetTime,OffsetDateTime,Instant, orYearDateorCalendar,java.sql.Date,java.sql.Time, orjava.sql.Timestamp,byte[]orByte[],char[]orCharacter[],- a Java
enumtype, or - any other
serializabletype.
The use of the Basic annotation is optional for persistent fields and properties of these types. If the Basic annotation is not specified for such a field or property, the default values of the Basic annotation apply.
The database column mapped by the persistent field or property may be specified using the Column annotation.
Example 1:
@Basic protected String name;
Example 2:
@Basic(fetch = LAZY) protected String getName() { return name; }
The use of Date, Calendar, java.sql.Date, java.sql.Time, java.sql.Timestamp, Character[], or Byte[] as the type of a basic attribute is now discouraged. Newly-written code should use the date/time types defined in the package java.time, or the primitive array types char[] and byte[].
- Since:
- Jakarta Persistence (JPA) 1.0
Annotation Elements
- The
EAGERstrategy is a requirement on the persistence provider runtime that the associated entity must be eagerly fetched. - The
LAZYstrategy is a hint to the persistence provider runtime.
If not specified, defaults to EAGER.
- Default:
FetchType.EAGER
- Since:
- Jakarta Persistence (JPA) 1.0
boolean optionalThis is a hint and is disregarded for primitive types; it may be used in schema generation to infer that the mapped column is not null.
If not specified, defaults to true.
- Default:
- true
- Since:
- Jakarta Persistence (JPA) 1.0
Additional JDK methods inherited from java.lang.annotation.Annotation
annotationType(), equals(Object), hashCode(), toString()