Hi,
I have created indices for associated javabeans.They are related by OneToMany/ManyToOne as follows:
Code Snippet:
@Entity
@Table(name = "subscriberprofile", catalog = "cloudcoredb")
@Indexed(index="subscriberprofile")
public class Subscriberprofile implements java.io.Serializable {
private long subscriberProfileId;
private String subscriberName;
private String susbcriberGender;
private Set addresses = new HashSet(0);
private int hashCode = Integer.MIN_VALUE;
// Constructors
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "subscriberProfileId", unique = true, nullable = false)
@DocumentId
public long getSubscriberProfileId() {
return this.subscriberProfileId;
}
public void setSubscriberProfileId(long subscriberProfileId) {
this.subscriberProfileId = subscriberProfileId;
}
@Column(name = "subscriberName", nullable = false, length = 30)
public String getSubscriberName() {
return this.subscriberName;
}
public void setSubscriberName(String subscriberName) {
this.subscriberName = subscriberName;
}
@Column(name = "susbcriberGender", length = 4)
@Field(index = Index.TOKENIZED, store = Store.YES)
public String getSusbcriberGender() {
return this.susbcriberGender;
}
public void setSusbcriberGender(String susbcriberGender) {
this.susbcriberGender = susbcriberGender;
}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "subscriberprofile", targetEntity=Address.class)
@ContainedIn
public Set getAddresses() {
return this.addresses;
}
public void setAddresses(Set addresses) {
this.addresses = addresses;
}
.....
......
} //End of class
[u][b]ANOTHER CLASS:[/b][/u]
@Entity
@Table(name = "address", catalog = "cloudcoredb")
@Indexed(index="address")
public class Address implements java.io.Serializable {
private long addressId;
private Subscriberprofile subscriberprofile;
private String city;
private String postalCode;
private String state;
// ........ Constructors.......................
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "AddressID", unique = true, nullable = false)
@DocumentId
public long getAddressId() {
return this.addressId;
}
public void setAddressId(long addressId) {
this.addressId = addressId;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "AddressTypeID", nullable = false)
@IndexedEmbedded
public Addresstype getAddresstype() {
return this.addresstype;
}
public void setAddresstype(Addresstype addresstype) {
this.addresstype = addresstype;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "subscriberProfileId", nullable = false)
@IndexedEmbedded
public Subscriberprofile getSubscriberprofile() {
return this.subscriberprofile;
}
public void setSubscriberprofile(Subscriberprofile subscriberprofile) {
this.subscriberprofile = subscriberprofile;
}
@Column(name = "City", nullable = false, length = 40)
@Field(index = Index.TOKENIZED, store = Store.YES)
public String getCity() {
return this.city;
}
public void setCity(String city) {
this.city = city;
}
@Column(name = "State", nullable = false, length = 40)
@Field(index = Index.TOKENIZED, store = Store.YES)
public String getState() {
return this.state;
}
public void setState(String state) {
this.state = state;
}
Query goal : To get list of Subscriberprofile object for location is equal to "bangalore"
The query i used in the code is
[code]
org.apache.lucene.search.Query luceneQuery = parser.parse("city:bangalore");
org.hibernate.Query fullTextQuery = textSession.createFullTextQuery(luceneQuery,Subscriberprofile.class);
[/code]
Here i am not getting any result but When i write Address.class instead of Subscriberprofile.class, i get a list of Address Object. But my aim is to get everything in terms of Subscriberprofile object whatever query criteria i use .
For this reason i am moving to another alternative called DBSight. Another reason to move to DBSight is that it creats inices for data already present in database.But in case of hibernate search, it creates index at the time of insertion to database.
I hope someone will surely reply with correct and uptodated info.
|