我有以下
package model.database;
import static javax.persistence.GenerationType.IDENTITY;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table( name = "DB_ACCOUNT_BILLING" )
public class AccountBilling implements Serializable
{
/**
*
*/
private static final long serialVersionUID = 1L;
private long userId;
private String firstName;
private String lastName;
private String username;
private String password;
public AccountBilling()
{
}
@Id
@GeneratedValue( strategy = IDENTITY )
@Column( name = "USER_ID", unique = true, nullable = false )
public long getUserId()
{
return userId;
}
public void setUserId( long userId )
{
this.userId = userId;
}
@Column( name = "FIRST_NAME", unique = false, nullable = false, length = 20 )
public String getFirstName()
{
return firstName;
}
public void setFirstName( String firstName )
{
this.firstName = firstName;
}
@Column( name = "LAST_NAME", unique = false, nullable = false, length = 20 )
public String getLastName()
{
return lastName;
}
public void setLastName( String lastName )
{
this.lastName = lastName;
}
@Column( name = "USERNAME", unique = true, nullable = false, length = 20 )
public String getUsername()
{
return username;
}
public void setUsername( String username )
{
this.username = username;
}
@Column( name = "PASSWORD", unique = false, nullable = false, length = 20 )
public String getPassword()
{
return password;
}
public void setPassword( String password )
{
this.password = password;
}
}
我想将用户名作为二级索引,但我不确定我应该使用什么 Hibernate 注释来指定它。另外,目前对于主索引检索,我执行以下操作:
session.beginTransaction();
AccountBilling accountBilling = (AccountBilling) session.get( AccountBilling.class, (long) primaryIndex );
但是我怎么能做二级索引检索呢?
任何帮助/建议将不胜感激。