Integrating JPA instances in the spring framework

Source: Internet
Author: User

Hibernate 3.2 supports JPA annotations, and spring integration JPA is optional.

The following is an example of the spring integration JPA.

Entity class MyUser, using JPA annotations to implement mappings to database table MyUser, as follows:

Package org.shirdrn.entity;
Import Java.util.Date;
Import Javax.persistence.Column;
Import javax.persistence.Entity;
Import Javax.persistence.GeneratedValue;
Import Javax.persistence.GenerationType;
Import Javax.persistence.Id;
Import javax.persistence.Transient;
@Entity
public class MyUser {
Private Long ID;
Private String UserName;
private String password;
Private String gender;
Private Integer age;
Private Integer birthyear;
Private String addr;
Private String Email;
@Id
@GeneratedValue (strategy = generationtype.identity)
Public Long getId () {
return ID;
}
public void SetId (Long id) {
This.id = ID;
}
@Column (name= "UserName")
Public String GetUserName () {
return userName;
}
public void Setusername (String userName) {
This.username = UserName;
}
@Column (name= "password")
Public String GetPassword () {
return password;
}
public void SetPassword (String password) {
This.password = password;
}
@Column (name= "gender")
Public String Getgender () {
return gender;
}
public void Setgender (String gender) {
This.gender = gender;
}
@Column (name= "age")
Public Integer Getage () {
return age;
}
public void Setage (Integer age) {
This.age = age;
}
@Column (name= "addr")
Public String getaddr () {
return addr;
}
public void setaddr (String addr) {
this.addr = addr;
}
@Column (name= "email")
Public String Getemail () {
return email;
}
public void Setemail (String email) {
This.email = email;
}
@Transient
Public Integer Getbirthyear () {
return new Integer (2008-age);
}
public void Setbirthyear (Integer age) {
This.birthyear = new Integer (2008-age);
}
}

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.