嗨,我正在開發使用(JPA)的一個對象用戶的持久層,我在編輯器中編寫代碼,而不是使用春季休眠任何東西,我寫了下面的代碼,但它顯示包javax.persistence 。*;沒有找到我如何使這個工作可以任何人幫助。deveoping實體類使用JPA
這是我寫的類。
//import javax.persistence.*;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
@Entity(name = "USER") //Name of the entity
public class User implements Serializable
{
private int userId;
private String userName;
private String password;
private String firstName;
private String lastName;
private String roles;
@Id
@Column(name = "USER_ID", nullable = false)
public int getUserId()
{
return userId;
}
public void setUserId(int UserId)
{
this.userId = userId;
}
@Column(name = "USER_NAME", nullable = false)
public String getUserName()
{
return userName;
}
public void setUserName(int userName)
{
this.userName = userName;
}
@Column(name = "PASSWORD", nullable = false)
public String getPassword()
{
return password;
}
public void setPassword(int password)
{
this.password = password;
}
@Column(name = "FIRST_NAME", nullable = false)
public String getFirstName()
{
return firstName;
}
public void setFirstName(int firstName)
{
this.firstName = firstName;
}
@Column(name = "LAST_NAME", nullable = false)
public String getLastName()
{
return lastName;
}
public void setLastName(int lastName)
{
this.lastName = lastName;
}
@Column(name = "ROLES", nullable = false)
public String getRoles()
{
return roles;
}
public void setRoles(int roles)
{
this.roles = roles;
}
public User()
{
}
}
如果您還不知道,最新的Hibernate版本實現了JPA規範(它們不是彼此獨佔的)。 JPA的其他流行實現是eclipselink和toplink。 – gerrytan