-->
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.  [ 3 posts ] 
Author Message
 Post subject: composite-id: Object found in Search index but not in db
PostPosted: Tue Feb 10, 2009 1:33 pm 
Newbie

Joined: Fri Oct 10, 2008 9:17 am
Posts: 13
Hi,

I have a domain object that has a composite identifier and I'm having trouble retrieving the objects from the database, despite getting hits from the Search index. I'm using Hibernate Search annotations with Hibernate XML mappings.

I'm seeing this warning in the log:

[DEBUG] 17:17:39 ObjectLoaderHelper - Object found in Search index but not in database: class com.test.schema.entities.Course with Key: id1 - id2

Where "Key: id1 - id2" is the toString() method of the CoursePK object - indicating that the CoursePK is loaded correctly from the index - the values of the composite id are correct and match those in the database.

I'm able to call sessionFactory.getCurrentSession().load(Course.class, pk) on any given Course id and get the correct result.

I'm really confused as to why this is happening and can only assume it is a configuration issue. Any help would be appreciated.

Here are the Objects / mappings (I've removed most of the unnecessary code):

Course Object:

Code:
@Indexed
public class Course implements Cloneable, Serializable
{
   @DocumentId
   @FieldBridge(impl = CoursePKBridge.class)
   private CoursePK id;

   etc...

}



CoursePK Object:

Code:
public class CoursePK implements Serializable
{
   String courseCode;
   String vendorCode;
   
   public CoursePK() {
      super();
   }

   [getters and setters]

      @Override
   public boolean equals(Object other)
   {
      if ( !(other instanceof CoursePK) ) return false;
      CoursePK castOther = (CoursePK) other;
      return new EqualsBuilder()
               .append(this.getCourseCode(), castOther.getCourseCode())
               .append(this.getVendorCode(), castOther.getVendorCode())
               .isEquals();
   }
   
   @Override
   public int hashCode() {
      return new HashCodeBuilder()
               .append(getCourseCode()+getVendorCode())
               .toHashCode();
   }
}



CoursePKBridge:

Code:
public class CoursePKBridge implements TwoWayFieldBridge
{
   public Object get(String name, Document document)
   {
      CoursePK id = new CoursePK();
      Field field = document.getField( name + ".courseCode" );
      id.setCourseCode( field.stringValue() );
      field = document.getField( name + ".vendorCode" );
      id.setVendorCode( field.stringValue() );
      return id;
   }
   
   public String objectToString(Object object)
   {
      CoursePK id = (CoursePK) object;
      StringBuilder sb = new StringBuilder();
      sb.append( id.getCourseCode() )
      .append( id.getVendorCode() );
      return sb.toString();
   }
   
   public void set(String name, Object value, Document document, LuceneOptions luceneOptions)
   {
      CoursePK id = (CoursePK) value;
      Store store = luceneOptions.getStore();
      Index index = luceneOptions.getIndex();
      TermVector termVector = luceneOptions.getTermVector();
      Float boost = luceneOptions.getBoost();
      //store each property in a unique field
      Field field = new Field( name + ".courseCode", id.getCourseCode(), store, index, termVector );
      field.setBoost( boost );
      document.add( field );
      field = new Field( name + ".vendorCode", id.getVendorCode(), store, index, termVector );
      field.setBoost( boost );
      document.add( field );
      //store the unique string representation in the named field
      field = new Field( name, objectToString( id ), store, index, termVector );
      field.setBoost( boost );
      document.add( field );
   }
}


Course XML Mapping:

Code:
<class name="Course" table="course" batch-size="30" dynamic-insert="true" dynamic-update="true" >
    <cache usage="read-write"/>
   
    <composite-id name="id" class="com.test.schema.entities.CoursePK">
       <key-property name="courseCode" column="course_code" />
       <key-property name="vendorCode" column="vendor_code_fk" />
    </composite-id>

    [property mappings...]

</class>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2009 7:33 am 
Newbie

Joined: Fri Oct 10, 2008 9:17 am
Posts: 13
I've been investigating some more and it appears the parameter values are not binding correctly.

Here's an example sql statement it is producing, with two matching results:


Code:
select this_.course_code as course1, this_.vendor_code_fk as user2, [other properties...] from course this_ where ((this_.course_code, this_.vendor_code_fk) in ( ( 'course-code-1', 'course-code-2'), ('vendor-code-1', 'vendor-code-2') ) )


It should populate the parameters in (course-code, vendor-code) pairs, but it is populating the first half with the course codes and the second lot with the vendor codes.

Is there any solution to this?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2009 1:01 pm 
Newbie

Joined: Fri Oct 10, 2008 9:17 am
Posts: 13
It appears to be the same issue encountered here:

http://forums.hibernate.org/viewtopic.php?t=992121

And submitted to JIRA here: http://opensource.atlassian.com/project ... SEARCH-306

Are there any known ways around this issue?


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