3

我刚开始玩休眠搜索。我该如何解决以下问题。

我所有从超类继承的java实体:

@SuppressWarnings("rawtypes")
@MappedSuperclass
@Indexed
public abstract class BaseEntity{

        private Integer id;
   private Integer jpaVersion;
   private Date creaDate;
   private Date modDate;
   private String creaUser;
   private String modUser;


        @Id
   @Column(name = "ID", unique = true, nullable = false, precision = 22, scale = 0)
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   public Integer getId() {
     return this.id;
   }

   public void setId(Integer id) {
     this.id = id;
   }   
   .....

例如,我必须(还有更多)子类:

@Entity
@Indexed
@Table(name = "BASE_PERSON", schema = "MYSCHEMA")
public class Person extends extends BaseEntity{

private String firstName;
private String lastName;
....
....

@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
  @Column(name = "LASTNAME", nullable = false, length = 50)
  @NotNull
  @Size(max=50)
  public String getLastName() {
    return this.lastName;
  }

  public void setLastName(String lastName) {
    this.lastName = lastName;
  }

  @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
  @Column(name = "FIRSTNAME", length = 50)
  @Size(max=50)
  public String getFirstName() {
    return this.firstName;
  }

  public void setFirstName(String firstName) {
    this.firstName = firstName;
  }

第二个:

@Entity
@Indexed
@Table(name = "BASE_USER", schema = "MYSCHEMA")
public class User extends extends BaseEntity{

private String userName;
....
....

@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
  @Column(name = "USERNAME", nullable = false, length = 50)
  @NotNull
  @Size(max=50)
  public String getUserName() {
    return this.userName;
  }

  public void setUserName(String lastName) {
    this.UserName = UserName;
  }

  ....

运行创建整个索引的代码后,我得到了三个索引。比我预想的多一个。索引是:BaseEntity、Person 和 User。但是所有 Persons 和 Useres 都存储在索引 BaseEntity 中,而不是它们自己的索引中。有没有办法改变这一点,以便所有人都在索引人员中,所有用户都在索引用户中?

或者这是休眠搜索的常见行为?

感谢和问候 LStrike

4

1 回答 1

4

您需要@Indexed从中删除BaseEntity,您只需要子类上的注释。您仍然可以用 with 注释属性BaseEntity@Field使它们出现在子类索引中。

于 2013-11-08T16:32:12.623 回答