-->
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.  [ 8 posts ] 
Author Message
 Post subject: Invalid or Corrupted Index
PostPosted: Wed Oct 22, 2008 5:33 pm 
Newbie

Joined: Wed Oct 22, 2008 5:22 pm
Posts: 7
I am getting Invalid or Corrupted Index when I try to index Person objects

@Indexed
public class Question implements Serializable {
private static final long serialVersionUID = 1L;
@DocumentId
private Long id;
@Field(index = Index.TOKENIZED, store = Store.NO)
private String fname;
@Field(index = Index.TOKENIZED, store = Store.NO)
private String lname;
}

This is my mapping
------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.ishi.clear.model">
<class name="Person" table="PERSON" optimistic-lock="version" discriminator-value="P">
<!-- <cache usage="read-write" /> -->
<id name="id" unsaved-value="null">
<generator class="native" />
</id>
<discriminator column="discriminator" type="character" />
<version name="version" type="long" />
<property name="fname" type="string" />
<property name="lname" type="string" />


<subclass name="Manager" extends="Question" discriminator-value="M">
<set name="employees" lazy="true" cascade="all">
<key column="personId" />
<one-to-many class="Employee" />
</set>
</subclass>

</class>
</hibernate-mapping>
--------------------------------
Indexing code

.....

public void indexPerson() {
HibernateCallback callback = new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
FullTextSession fullTextSession = Search.createFullTextSession(session);

List<DescriptiveQuestion> questions = session.createQuery("from Person as person ").list();

for (Person person: persons) {
System.out.println(question.getStatement());
fullTextSession.index(question);
}

return null;
}
};

getHibernateTemplate().execute(callback);
}
....
....


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2008 3:20 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

could you also post the stack trace? And are you sure that the configuration you posted is consistent? Where is the connection between Person and Question or even DescriptiveQuestion?

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2008 10:56 am 
Newbie

Joined: Wed Oct 22, 2008 5:22 pm
Posts: 7
My apologies it should look like this

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.ishi.clear.model">
<class name="Person" table="PERSON" optimistic-lock="version" discriminator-value="P">
<!-- <cache usage="read-write" /> -->
<id name="id" unsaved-value="null">
<generator class="native" />
</id>
<discriminator column="discriminator" type="character" />
<version name="version" type="long" />
<property name="fname" type="string" />
<property name="lname" type="string" />


<subclass name="Manager" extends="Person" discriminator-value="M">
<set name="employees" lazy="true" cascade="all">
<key column="personId" />
<one-to-many class="Employee" />
</set>
</subclass>

</class>
</hibernate-mapping>
--------------------------------
Indexing code

.....

public void indexManagers() {
HibernateCallback callback = new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
FullTextSession fullTextSession = Search.createFullTextSession(session);

List<Manager> persons = session.createQuery("from Manager as person ").list();

for (Manager person: persons) {
System.out.println(question.getStatement());
fullTextSession.index(question);
}

return null;
}
};

getHibernateTemplate().execute(callback);
}
....
....

Anyway it works actually the index is not corrupted instead it is not created; I tried to view the indices through Lukeall GUI so actually I don’t have any Exception stack trace. I have this question how do I index employees under the manager, I tried this query “from Manager as person JOIN FETCH employees “ but it only gives me Managers who really has employees (although in real world this is true), how to index managers along with employees although the managers doesn’t have any employees or in other words I need to build a query some thing like this “from Manager as person OUTER JOIN FETCH employees” i know OUTER is not a key word but how do i get outer joins?

Thanks for your valuable answer.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2008 11:28 am 
Newbie

Joined: Wed Oct 22, 2008 5:22 pm
Posts: 7
oops sorry again OUTER should be prepended with LEFT or RIGHT
but still the index is not indexing the collections from the Manager how to index the collection if I put

@Field anotation for employees
I am getting this exception

org.hibernate.search.SearchException: Unable to guess FieldBridge for employees


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2008 2:50 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

it would also be nice to see the annotated classes Manager and Employee. However, looking at the exception I assume you just annotated the employees collection in Manager with @Field. Instead you should use @IndexEmbedded and then in Employee you should annotate all fields you want to include into the index with @Field.

Alternatively, you can annotate employees with @Field, but then you also have to specify @fieldBridge in order to tell Hibernate Search how to index Employees.

I recommend you read the section about indexing clections in the onlnd docs. If you then still have questions, please post the annotated classes.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2008 4:29 pm 
Newbie

Joined: Wed Oct 22, 2008 5:22 pm
Posts: 7
hardy,
Thanks I have already resolved the issue with @IndexEmbedded and @ContainedIn annotations, I have to lookinto @fieldBridge since inorder to use @ContainedIn I need to use set of managers on Employee also which sounds odd.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2008 4:06 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

what is strange is that you say 'set of managers' in employee. A manager having a set of Employees, does not imply an Employee having to have a set of Managers. Instead a Employee can just have a link back to his Manager. This is a standard bidirectional link. I ma not sure why you think that is odd?

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2008 9:46 am 
Newbie

Joined: Wed Oct 22, 2008 5:22 pm
Posts: 7
Hardy,
I agree but what I meant was this

class Employee {
String name;
...
....
@ContainedIn
Set<Manager> managers;
}


well yes it's possible Employee can have old managers as part of their current managers so I agree, just need to do more readin on hibernate search. Thanks for the help.


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