-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: [Solved] Hibernate Search and inheritance
PostPosted: Fri Nov 08, 2013 6:39 am 
Beginner
Beginner

Joined: Fri Nov 08, 2013 6:26 am
Posts: 21
Location: Germany
Hello everyone,

I just started playing around with hibernate search.
How can I solve the following problem.

All my java entities where inherited from a superclass:

Code:
@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;
   }   
   .....



For example I have to (there are more) subclasses:

Code:
@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;
  }




and a second one


Code:
@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;
  }

  ....





After running the code for creating the whole index, I got three indexes. One more than I expected. The indexes are: BaseEntity, Person and User.
But all Persons and Useres ares stored in the index BaseEntity and not in their own index.
Is there a way to change this, so that all persons are in the index person and all users are in the index users?

Or is this the common behaviour of hibernate search?


Thanks and Regards
LStrike


Last edited by LStrike on Mon Nov 11, 2013 3:51 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Hibernate Search and inheritance
PostPosted: Mon Nov 11, 2013 3:51 am 
Beginner
Beginner

Joined: Fri Nov 08, 2013 6:26 am
Posts: 21
Location: Germany
Problem is solved by help from RandomMooCow @stackoverflow.

http://stackoverflow.com/questions/19857177/create-separate-hibernate-search-indexes-for-each-subclass


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.