-->
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.  [ 4 posts ] 
Author Message
 Post subject: What will be the query expression for ......
PostPosted: Thu Jul 12, 2007 7:46 am 
Newbie

Joined: Fri Apr 13, 2007 2:16 am
Posts: 11
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 12, 2007 9:02 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
As explained in the doc, it should be "addresses.city:bangalore".
Hibernate Search can index existing data of course:
http://www.hibernate.org/hib_docs/search/reference/en/html_single/#search-batchindex

There might be reasons to move to DBSight but those ones are clearly wrong.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 3:15 am 
Newbie

Joined: Fri Apr 13, 2007 2:16 am
Posts: 11
Hi Emmanuel,
Thanks for the reply, but still doubts persist in my miind
DO you mean that to create index for existing data, we need to retrieve and convert them to object first and then call following method:
fullTextSession.index(object);

Please comment on above written paragraph.

As you suggested i used addresses.city:bangalore, still did not get correct result.


But when i do other way round i mean when i use
org.apache.lucene.search.Query luceneQuery = parser.parse("subscriberprofile.susbcriberGender:male");
org.hibernate.Query fullTextQuery = textSession.createFullTextQuery(luceneQuery,Subscriberprofile.class,Address.class);

I get list of Address object( which offcourse i dont want).

IS IT SERIOUS BUG IN HIBERNATE SEARCH ????????????........


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 8:58 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Ah there were another error in your code

Code:
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "subscriberprofile", targetEntity=Address.class)
@IndexedEmbedded(depth=1) // not @ContainedIn
public Set getAddresses() {
return this.addresses;
}

and on the other side

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "subscriberProfileId", nullable = false)
@IndexedEmbedded(depth=1) //set this annotation only if you need to go from address to SubscriberProfile
public Subscriberprofile getSubscriberprofile() {
return this.subscriberprofile;
}


Check the reference doc on @IndexedEmbedded and @ContainedIn for more info on how to use them

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.