Hibernate field names and properties

Source: Internet
Author: User

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:
    1. <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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.