Using hibernate annotations, how to identify a field that has a property that is not a database

Source: Internet
Author: User

Using hibernate annotations, how to identify a property that is not a database field.
This means that an entity class corresponds to a table, but there is one attribute in the entity class that does not correspond to the field in the table

@Transient
Options available
@Transient indicates that the property is not a mapping to a field in a database table, the ORM framework ignores the property.
If a property is not a field mapping for a database table, it must be marked as @transient, otherwise the ORM framework defaults to its annotation as @basic
Example:
Calculates the age property based on birth
@Transient
public int getage () {
Return GetYear (New Date ())-getYear (birth);
}

If the field of a database map is a normal field, you need to add annotations

@Column (name = "PARAMNM", length = 50)
Public String GETPARAMNM ()
{
return THIS.PARAMNM;
}

Table ID words need to be added

@Id
  @GeneratedValue
  @Column (name = "Id", unique = true, Nullable = false, Precision = $, scale = 0
 public Long getId ()
 {
  return this.id;
 }

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.