-->
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: Hibernate Search: Indexing Inherited Fields
PostPosted: Thu Sep 11, 2008 2:54 pm 
Regular
Regular

Joined: Fri Oct 05, 2007 1:17 pm
Posts: 78
I have JPA entities in an inheritance relationship of the type InheritanceType.JOINED. The top-level class is an abstract Payment class, which has several concrete subclasses. Meanwhile, the Order class has an association with Payment.

The Order class is indexed since I want to search for orders on various fields the Order class has, but I also want to search for orders on the single Payment attribute that all payments have.

Here is some code:

Order.java
Code:
@Entity
@Table(name = "WIDGET_ORDER")
@Indexed
public class Order {
.
.
.
   @OneToOne(fetch= FetchType.LAZY, cascade= CascadeType.PERSIST)   
   @JoinColumn(name = "PAYMENT_ID", nullable = true)
   public Payment getPayment() {
      return payment;
   }
.
.
.
}


Payment.java
Code:
@Entity
@Table(name = "PAYMENT")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Payment  {
.
.
.
   @Column(name = "COMMON_PAYMENT_ATTRIBUTE", nullable = true)
   public String getCommonPaymentAttribute() {
      return commonPaymentAttribute;
   }
.
.
.

}



I am curious about how I can search for orders based on payments. Do I apply @Indexed at the Payment level or at the subclass level? And where do I apply @Field and @Boost? At the Payment level? Or do I override the getCommonPaymentAttribute method at the subclass level and apply the annotations to each method?

Any insight here is appreciated.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2008 3:37 pm 
Regular
Regular

Joined: Fri Oct 05, 2007 1:17 pm
Posts: 78
I made the following changes:

Order.java
Code:
   @OneToOne(fetch= FetchType.LAZY, cascade= CascadeType.PERSIST)
   @JoinColumn(name = "PAYMENT_ID", nullable = true)
   @IndexedEmbedded
   public Payment getPayment() {
      return payment;
   }


and in Payment.java
Code:
@Entity
@Table(name = "PAYMENT")
@Inheritance(strategy = InheritanceType.JOINED)
@Indexed
public abstract class Payment  {
.
.
.
   @Id
   @GeneratedValue(strategy = GenerationType.SEQUENCE)
   @Column(name = "ID")
   @DocumentId
   public Long getId() {
      return super.getId();
   }

   @Column(name = "COMMON_PAYMENT_ATTRIBUTE", nullable = true)
   @Field(index = Index.UN_TOKENIZED, store = Store.NO)
   @Boost(5f)
   public String getCommonPaymentAttribute() {
      return commonPaymentAttribute;
   }
.
.
.

}


Meanwhile, none of the concrete classes are annotated in any way related to Hibernate Search.

When I generate the indexes and take a look at them with Luke, Order cannot see Payment at all.

Any help is appreciated.

Thanks.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.