-->
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: Hibernate Search, Embedded Object error
PostPosted: Thu Nov 29, 2007 7:30 am 
Newbie

Joined: Thu Nov 29, 2007 7:15 am
Posts: 7
Hi,

I have an Entity with a Composite Key (composite key made up of two Long variables).
Here is a snippet of the error that I get when I execute a search.

java.lang.NumberFormatException: For input string: "com.faculte.hibernateobjects.FaculteClassPK@72add8[User-id=1,Class-id=2]"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:447)
at java.lang.Integer.<init>(Integer.java:620)
at org.hibernate.search.bridge.builtin.IntegerBridge.stringToObject(IntegerBridge.java:14)
at org.hibernate.search.bridge.TwoWayString2FieldBridgeAdaptor.get(TwoWayString2FieldBridgeAdaptor.java:32)
at org.hibernate.search.engine.DocumentBuilder.getDocumentId(DocumentBuilder.java:626)
at org.hibernate.search.engine.DocumentExtractor.extract(DocumentExtractor.java:30)
at org.hibernate.search.engine.DocumentExtractor.extract(DocumentExtractor.java:40)
at org.hibernate.search.query.FullTextQueryImpl.list(FullTextQueryImpl.java:241)
at com.faculte.dao.SearchDAO.findClasses(SearchDAO.java:175)
at com.faculte.dao.SearchDAO.searchClasses(SearchDAO.java:359)


Here is the Model that I use -

@Indexed(index="indexes/faculteclass")
public class FaculteClass implements Serializable, IClassInfo {

private FaculteClassPK i_id;

private ClassType i_classType;

@Field(index=Index.TOKENIZED, store=Store.YES)
private String i_title;

@Field(index=Index.TOKENIZED, store=Store.YES)
private String i_description;

@DocumentId
private int i_noOfChapters;

private double i_price;
......

public class FaculteClassPK implements Serializable {

private Long i_userId;

private Long i_classId;
....


Any idea why this Number format error is being thrown?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 29, 2007 7:39 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
Looking at the exception, I believe that, value being passed for parsing to Integer.parseInt is com.faculte.hibernateobjects.FaculteClassPK@72add8[User-id=1,Class-id=2]
thats all I can guess from information available in post.

_________________
Please rate this post if you find it helpful


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 29, 2007 4:17 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Actually @DocumentId must point to the Entity id, not any random property

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Document ID Fieldbridge issue
PostPosted: Fri Nov 30, 2007 1:39 am 
Newbie

Joined: Thu Nov 29, 2007 7:15 am
Posts: 7
Hi,

Thanks for the earlier reply.
I think you hit the nail on the head with that "Actually @DocumentId must point to the Entity id, not any random property".

Now, the changes that I have done are as follows -
I have now made FaculteClassPK the DocumentID as required (because that is the actual Entity ID).

@DocumentId
@IndexedEmbedded
@FieldBridge(impl = FaculteClassPKBridge.class)
private FaculteClassPK i_id;

I have implemented a FaculteClassPKBridge as follows -
public class FaculteClassPKBridge implements StringBridge {

public String objectToString(Object object) {
String rawString = ( (FaculteClassPK) object ).toString();
return rawString;
}
}

The FaculteClassPK has a toString Method that is -
public String toString() {
return new ToStringBuilder(this).append("User-id", i_userId).append(
"Class-id", i_classId).toString();
}

With this, I am now getting the following error -

org.hibernate.search.SearchException: Bridge for document id does not implement IdFieldBridge: i_id
at org.hibernate.search.engine.DocumentBuilder.initializeMember(DocumentBuilder.java:192)
at org.hibernate.search.engine.DocumentBuilder.initializeMembers(DocumentBuilder.java:167)



Anything that I'm missing out here?

Regards,
-rahul


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 30, 2007 2:12 am 
Newbie

Joined: Thu Nov 29, 2007 7:15 am
Posts: 7
Figured that one. Need to implement a TwoWayStringBridge.

Am doing that now, but the stringToObject(String arg0) is throwing a null pointer exception.
Basically, the arg0 is null so thats an issue, but why is it null is something that I am unable to figure out.

Any inputs?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 30, 2007 10:33 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
um strange, if you find some more info by debuging let me know. null should never be returned.
Check that the id field is properly saved in the Lucene index (using luke for example)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 02, 2007 4:18 am 
Newbie

Joined: Thu Nov 29, 2007 7:15 am
Posts: 7
Hi,

Fixed the problem. As suspected it was an indexing issue.
Here is the observation
Lets say there is a field named i_Id which needs to be indexed.
I am using hbms as of now and have mapped this i_Id to the mapping name 'id'.
This seems to create a problem while indexing incase the i_Id is also my @DocumentId.

I changed the field name from i_Id to 'id' and things worked perfectly.

Would be eager to know any more details on why that occurs.

Thanks
-rahul


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 02, 2007 1:50 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Rahul Sachdev wrote:
Lets say there is a field named i_Id which needs to be indexed.
I am using hbms as of now and have mapped this i_Id to the mapping name 'id'.

I don't understand :)

_________________
Emmanuel


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