Field name and property name are the same
Annotation: Default is @basic
Note: If no annotations are added to the member properties, the default is to precede the @Basic
Do not write column in XML
Field name and property name are different
Annotation: Annotate with @Column (name= "ColumnName")
For example:
*@Entity indicates that the following teacher is an entity class* @Table represents a table name that is mapped to a data table, where the name parameter represents"Table name"*@Column represents the field name in the Entity class Member property mapping data table, where the name parameter specifies a new field name*@Id represents the primary key Id*/@Entity @Table (name="_teacher") Public classTeacher {Private intID; PrivateString name; PrivateString title; //set Primary key using @id@Id Public intgetId () {returnID; } @Column (Name="_name")//field names are not the same as properties PublicString GetName () {returnname; } ...
Xml:
- <property name= "name" column= "_name"/>
fields that do not require (persist) Psersistence
Is that a member property of a non-entity class does not need to be stored in the database
Annotation: Use the @Transient to annotate it.
For example:
@Transient public String getTitle () { return title; }
XML: Do not write (that is, you do not need to map this member property)
mapping date and time types, specifying time precision
Annotation: Use the @Temporal (value=temporaltype) to annotate annotations that represent dates and times
Where Temporaltype has three values: Temporaltype.timestamp represents YYYY-MM-DD HH:mm:ss
Temporaltype.date says YYYY-MM-DD
Temporaltype.time says HH:MM:SS
@Temporal (value=temporaltype.date) public DATE getbirthdate () { return birthDate;
Note: When using annotations, this property name can be omitted when the property is value, for example:@Temporal (Temporaltype)
XML: Use the Type property to specify the hibernate type
<property name="birthDate" type="date"
Note: Hibernate datetime types are: date, time, timestamp, and of course you can also use the Java wrapper class
Mapping enumeration types
Annotation: Use the @Enumerated (value=enumtype) to annotate this member property to map the enumeration to the database
Where Enumtype has two values: ①enumtype.string indicates that the enumeration name is stored directly in the database
②enumtype.ordinal indicates that the value corresponding to the enumeration is stored in the database
XML: Mapping is very troublesome, first define a custom type, and then use the type of the definition ...
Http://blog.sina.com.cn/s/blog_4979ec3e01016y0o.html
Hibernate field names and properties