<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <base href="https://hibernate.atlassian.net" />
<title>Message Title</title>
</head>
<body class="jira" style="color: #333; font-family: Arial, sans-serif; font-size: 14px; line-height: 1.429">
<table id="background-table" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background-color: #f5f5f5; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<!-- header here -->
<tr>
<td id="header-pattern-container" style="padding: 0px; border-collapse: collapse; padding: 10px 20px">
<table id="header-pattern" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tr>
<td id="header-avatar-image-container" valign="top" style="padding: 0px; border-collapse: collapse; vertical-align: top; width: 32px; padding-right: 8px"> <img id="header-avatar-image" class="image_fix" src="https://secure.gravatar.com/avatar/71981c9f6b89bada08afac7477ac2dec?d=mm&s=48" height="32" width="32" border="0" style="border-radius: 3px; vertical-align: top" />
</td>
<td id="header-text-container" valign="middle" style="padding: 0px; border-collapse: collapse; vertical-align: middle; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px"> <a class="user-hover" rel="crancran" id="email_crancran" href="https://hibernate.atlassian.net/secure/ViewProfile.jspa?name=crancran" style="color:#6c797f;; color: #3b73af; text-decoration: none">Chris Cranford</a> <strong>commented</strong> on an issue
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td id="email-content-container" style="padding: 0px; border-collapse: collapse; padding: 0 20px">
<table id="email-content-table" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; border-spacing: 0; border-collapse: separate">
<tr>
<!-- there needs to be content in the cell for it to render in some clients -->
<td class="email-content-rounded-top mobile-expand" style="padding: 0px; border-collapse: collapse; color: #fff; padding: 0 15px 0 16px; height: 15px; background-color: #fff; border-left: 1px solid #ccc; border-top: 1px solid #ccc; border-right: 1px solid #ccc; border-bottom: 0; border-top-right-radius: 5px; border-top-left-radius: 5px; height: 10px; line-height: 10px; padding: 0 15px 0 16px; mso-line-height-rule: exactly">
</td>
</tr>
<tr>
<td id="text-paragraph-pattern-top" class="email-content-main mobile-expand comment-top-pattern" style="padding: 0px; border-collapse: collapse; border-left: 1px solid #ccc; border-right: 1px solid #ccc; border-top: 0; border-bottom: 0; padding: 0 15px 15px 16px; background-color: #fff; border-bottom: 1px solid #ccc; border-bottom: none; padding-bottom: 0px">
<table class="text-paragraph-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 2px">
<tr>
<td class="text-paragraph-pattern-container mobile-resize-text" style="padding: 0px; border-collapse: collapse; padding: 0px; padding-left: 16px; padding-bottom: 10px; border-left: 1px solid #ccc">
<p style="margin: 10px 0 0 0">Per Emmanuel's suggestion, I tried the jTDS driver and I observe the same behavior. </p>
<p style="margin: 10px 0 0 0">I am going to attach various parts of my code to help illustrate what we have here in case there potentially is a mapping or implementation issue from our end on how we're using Hibernate ORM and Search modules that are leading to this unusual behavior with composite keys.</p>
<div class="code panel" style="border-width: 1px;; border: 1px solid #ccc; background: #f5f5f5; font-size: 12px; line-height: 1.333; font-family: monospace; border: 1px solid #ccc; -moz-border-radius: 3px 3px 3px 3px; border-radius: 3px 3px 3px 3px; margin: 9px 0">
<div class="codeHeader panelHeader" style="border-bottom-width: 1px;; border-bottom: 1px solid #ccc; padding: 9px 12px">
<b>ItemId.java</b>
</div>
<div class="codeContent panelContent" style="padding: 9px 12px">
<pre class="code-java" style="margin: 10px 0 0 0; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal"><span class="code-keyword" style="color: #000091">package</span> com.setech.dw.inventory.domain;
<span class="code-keyword" style="color: #000091">import</span> java.io.Serializable;
<span class="code-keyword" style="color: #000091">import</span> javax.persistence.Column;
<span class="code-keyword" style="color: #000091">import</span> javax.persistence.Embeddable;
<span class="code-keyword" style="color: #000091">import</span> javax.persistence.MappedSuperclass;
<span class="code-keyword" style="color: #000091">import</span> org.apache.commons.lang3.builder.EqualsBuilder;
<span class="code-keyword" style="color: #000091">import</span> org.apache.commons.lang3.builder.HashCodeBuilder;
@Embeddable
@MappedSuperclass
<span class="code-keyword" style="color: #000091">public</span> class ItemId <span class="code-keyword" style="color: #000091">implements</span> Serializable {
<span class="code-keyword" style="color: #000091">private</span> <span class="code-keyword" style="color: #000091">static</span> <span class="code-keyword" style="color: #000091">final</span> <span class="code-object" style="color: #910091">long</span> serialVersionUID = 240673572700126892L;
<span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">Long</span> itemId;
<span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">Long</span> plantId;
@Column(name=<span class="code-quote" style="color: #009100">"ITEM_ID"</span>,unique=<span class="code-keyword" style="color: #000091">false</span>,nullable=<span class="code-keyword" style="color: #000091">false</span>,insertable=<span class="code-keyword" style="color: #000091">true</span>,updatable=<span class="code-keyword" style="color: #000091">false</span>)
<span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">Long</span> getItemId() {
<span class="code-keyword" style="color: #000091">return</span> itemId;
}
<span class="code-keyword" style="color: #000091">public</span> void setItemId(<span class="code-object" style="color: #910091">Long</span> itemId) {
<span class="code-keyword" style="color: #000091">this</span>.itemId = itemId;
}
@Column(name=<span class="code-quote" style="color: #009100">"PLANT_ID"</span>,unique=<span class="code-keyword" style="color: #000091">false</span>,nullable=<span class="code-keyword" style="color: #000091">false</span>,insertable=<span class="code-keyword" style="color: #000091">true</span>,updatable=<span class="code-keyword" style="color: #000091">false</span>)
<span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">Long</span> getPlantId() {
<span class="code-keyword" style="color: #000091">return</span> plantId;
}
<span class="code-keyword" style="color: #000091">public</span> void setPlantId(<span class="code-object" style="color: #910091">Long</span> plantId) {
<span class="code-keyword" style="color: #000091">this</span>.plantId = plantId;
}
@Override
<span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">int</span> hashCode() {
<span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">new</span> HashCodeBuilder(17,31)
.append(getItemId())
.append(getPlantId())
.toHashCode();
}
@Override
<span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">boolean</span> equals(<span class="code-object" style="color: #910091">Object</span> object) {
<span class="code-keyword" style="color: #000091">if</span>(!(object <span class="code-keyword" style="color: #000091">instanceof</span> ItemId)) <span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">false</span>;
ItemId other = (ItemId) object;
<span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">new</span> EqualsBuilder()
.append(getItemId(), other.getItemId())
.append(getPlantId(), other.getPlantId())
.isEquals();
}
}
</pre>
</div>
</div>
<div class="code panel" style="border-width: 1px;; border: 1px solid #ccc; background: #f5f5f5; font-size: 12px; line-height: 1.333; font-family: monospace; border: 1px solid #ccc; -moz-border-radius: 3px 3px 3px 3px; border-radius: 3px 3px 3px 3px; margin: 9px 0">
<div class="codeHeader panelHeader" style="border-bottom-width: 1px;; border-bottom: 1px solid #ccc; padding: 9px 12px">
<b>ItemTest.java</b>
</div>
<div class="codeContent panelContent" style="padding: 9px 12px">
<pre class="code-java" style="margin: 10px 0 0 0; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal"><span class="code-keyword" style="color: #000091">package</span> com.setech.dw.inventory.domain;
<span class="code-keyword" style="color: #000091">import</span> java.io.Serializable;
<span class="code-keyword" style="color: #000091">import</span> javax.persistence.Column;
<span class="code-keyword" style="color: #000091">import</span> javax.persistence.Entity;
<span class="code-keyword" style="color: #000091">import</span> javax.persistence.GeneratedValue;
<span class="code-keyword" style="color: #000091">import</span> javax.persistence.Id;
<span class="code-keyword" style="color: #000091">import</span> javax.persistence.Table;
<span class="code-keyword" style="color: #000091">import</span> org.apache.commons.lang3.builder.EqualsBuilder;
<span class="code-keyword" style="color: #000091">import</span> org.apache.commons.lang3.builder.HashCodeBuilder;
<span class="code-keyword" style="color: #000091">import</span> org.hibernate.search.annotations.Analyze;
<span class="code-keyword" style="color: #000091">import</span> org.hibernate.search.annotations.Analyzer;
<span class="code-keyword" style="color: #000091">import</span> org.hibernate.search.annotations.Field;
<span class="code-keyword" style="color: #000091">import</span> org.hibernate.search.annotations.Fields;
<span class="code-keyword" style="color: #000091">import</span> org.hibernate.search.annotations.Index;
<span class="code-keyword" style="color: #000091">import</span> org.hibernate.search.annotations.Indexed;
<span class="code-keyword" style="color: #000091">import</span> org.hibernate.search.annotations.Store;
<span class="code-keyword" style="color: #000091">import</span> com.setech.lucene.analysis.PartNumberRemoveSpecialCharactersAnalyzer;
@Entity
@Table(name=<span class="code-quote" style="color: #009100">"test_items"</span>)
@Indexed
<span class="code-keyword" style="color: #000091">public</span> class ItemTest <span class="code-keyword" style="color: #000091">implements</span> Serializable {
<span class="code-keyword" style="color: #000091">private</span> <span class="code-keyword" style="color: #000091">static</span> <span class="code-keyword" style="color: #000091">final</span> <span class="code-object" style="color: #910091">long</span> serialVersionUID = 6263726165830649600L;
<span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">Long</span>          id;
<span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">String</span> itemNumber;
<span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">String</span> description;
        
@Id
@GeneratedValue
@Column(name=<span class="code-quote" style="color: #009100">"ITEM_ID"</span>)
<span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">Long</span> getId() {
<span class="code-keyword" style="color: #000091">return</span> id;
}
<span class="code-keyword" style="color: #000091">public</span> void setId(<span class="code-object" style="color: #910091">Long</span> id) {
<span class="code-keyword" style="color: #000091">this</span>.id = id;
}
        
@Fields({
@Field(name=<span class="code-quote" style="color: #009100">"itemTestItemNumber"</span>,index=Index.YES, analyze=Analyze.YES, store=Store.YES, analyzer=@Analyzer(definition=<span class="code-quote" style="color: #009100">"keywordLowerCaseAnalyzer"</span>)),
@Field(name=<span class="code-quote" style="color: #009100">"itemTestItemNumberScrubbed"</span>, index=Index.YES, analyze=Analyze.YES, store=Store.NO, analyzer=@Analyzer(impl=PartNumberRemoveSpecialCharactersAnalyzer.class))
})
@Column(name=<span class="code-quote" style="color: #009100">"ITEM_NUMBER"</span>,length=80,nullable=<span class="code-keyword" style="color: #000091">false</span>,insertable=<span class="code-keyword" style="color: #000091">true</span>,updatable=<span class="code-keyword" style="color: #000091">true</span>)
<span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">String</span> getItemNumber() {
<span class="code-keyword" style="color: #000091">return</span> itemNumber;
}
<span class="code-keyword" style="color: #000091">public</span> void setItemNumber(<span class="code-object" style="color: #910091">String</span> itemNumber) {
<span class="code-keyword" style="color: #000091">this</span>.itemNumber = itemNumber;
}
        
@Column(name=<span class="code-quote" style="color: #009100">"DESCRIPTION"</span>,length=240,nullable=<span class="code-keyword" style="color: #000091">true</span>,insertable=<span class="code-keyword" style="color: #000091">true</span>,updatable=<span class="code-keyword" style="color: #000091">true</span>)
@Field(name=<span class="code-quote" style="color: #009100">"itemTestDescription"</span>, index=Index.YES, analyze=Analyze.YES, store=Store.YES)
<span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">String</span> getDescription() {
<span class="code-keyword" style="color: #000091">return</span> description;
}
<span class="code-keyword" style="color: #000091">public</span> void setDescription(<span class="code-object" style="color: #910091">String</span> description) {
<span class="code-keyword" style="color: #000091">this</span>.description = description;
}
        
@Override
<span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">int</span> hashCode() {
<span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">new</span> HashCodeBuilder(17,31)
.append(getId())
        .append(getItemNumber())
        .append(getDescription())
        .toHashCode();
}
        
@Override
<span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">boolean</span> equals(<span class="code-object" style="color: #910091">Object</span> object) {
<span class="code-keyword" style="color: #000091">if</span>(!(object <span class="code-keyword" style="color: #000091">instanceof</span> ItemTest)) <span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">false</span>;
ItemTest other = (ItemTest) object;
<span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">new</span> EqualsBuilder()        
        .append(getId(), other.getId())
        .append(getItemNumber(), other.getItemNumber())
        .append(getDescription(), other.getDescription())
        .isEquals();
}
}
</pre>
</div>
</div>
<div class="code panel" style="border-width: 1px;; border: 1px solid #ccc; background: #f5f5f5; font-size: 12px; line-height: 1.333; font-family: monospace; border: 1px solid #ccc; -moz-border-radius: 3px 3px 3px 3px; border-radius: 3px 3px 3px 3px; margin: 9px 0">
<div class="codeHeader panelHeader" style="border-bottom-width: 1px;; border-bottom: 1px solid #ccc; padding: 9px 12px">
<b>ItemTestA.java</b>
</div>
<div class="codeContent panelContent" style="padding: 9px 12px">
<pre class="code-java" style="margin: 10px 0 0 0; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal"><span class="code-keyword" style="color: #000091">package</span> com.setech.dw.inventory.domain;
<span class="code-keyword" style="color: #000091">import</span> java.io.Serializable;
<span class="code-keyword" style="color: #000091">import</span> javax.persistence.AttributeOverride;
<span class="code-keyword" style="color: #000091">import</span> javax.persistence.AttributeOverrides;
<span class="code-keyword" style="color: #000091">import</span> javax.persistence.Column;
<span class="code-keyword" style="color: #000091">import</span> javax.persistence.EmbeddedId;
<span class="code-keyword" style="color: #000091">import</span> javax.persistence.Entity;
<span class="code-keyword" style="color: #000091">import</span> javax.persistence.Table;
<span class="code-keyword" style="color: #000091">import</span> org.apache.commons.lang3.builder.EqualsBuilder;
<span class="code-keyword" style="color: #000091">import</span> org.apache.commons.lang3.builder.HashCodeBuilder;
<span class="code-keyword" style="color: #000091">import</span> org.hibernate.search.annotations.Analyze;
<span class="code-keyword" style="color: #000091">import</span> org.hibernate.search.annotations.Analyzer;
<span class="code-keyword" style="color: #000091">import</span> org.hibernate.search.annotations.DocumentId;
<span class="code-keyword" style="color: #000091">import</span> org.hibernate.search.annotations.Field;
<span class="code-keyword" style="color: #000091">import</span> org.hibernate.search.annotations.FieldBridge;
<span class="code-keyword" style="color: #000091">import</span> org.hibernate.search.annotations.Fields;
<span class="code-keyword" style="color: #000091">import</span> org.hibernate.search.annotations.Index;
<span class="code-keyword" style="color: #000091">import</span> org.hibernate.search.annotations.Indexed;
<span class="code-keyword" style="color: #000091">import</span> org.hibernate.search.annotations.Store;
<span class="code-keyword" style="color: #000091">import</span> com.setech.hibernate.search.bridge.ItemIdBridge;
<span class="code-keyword" style="color: #000091">import</span> com.setech.lucene.analysis.PartNumberRemoveSpecialCharactersAnalyzer;
@Entity
@Table(name=<span class="code-quote" style="color: #009100">"test_items2"</span>)
@Indexed
<span class="code-keyword" style="color: #000091">public</span> class ItemTestA <span class="code-keyword" style="color: #000091">implements</span> Serializable {
<span class="code-keyword" style="color: #000091">private</span> <span class="code-keyword" style="color: #000091">static</span> <span class="code-keyword" style="color: #000091">final</span> <span class="code-object" style="color: #910091">long</span> serialVersionUID = 299977430325200598L;
<span class="code-keyword" style="color: #000091">private</span> ItemId id;
<span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">String</span> itemNumber;
<span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">String</span> description;
        
@EmbeddedId
@AttributeOverrides({
                @AttributeOverride(name=<span class="code-quote" style="color: #009100">"itemId"</span>, column=@Column(name=<span class="code-quote" style="color: #009100">"ITEM_ID"</span>, unique=<span class="code-keyword" style="color: #000091">false</span>, nullable=<span class="code-keyword" style="color: #000091">false</span>, insertable=<span class="code-keyword" style="color: #000091">true</span>, updatable=<span class="code-keyword" style="color: #000091">true</span>, scale=0)),
                @AttributeOverride(name=<span class="code-quote" style="color: #009100">"plantId"</span>, column=@Column(name=<span class="code-quote" style="color: #009100">"PLANT_ID"</span>, unique=<span class="code-keyword" style="color: #000091">false</span>, nullable=<span class="code-keyword" style="color: #000091">false</span>, insertable=<span class="code-keyword" style="color: #000091">true</span>, updatable=<span class="code-keyword" style="color: #000091">true</span>, scale=0))
                }
        )
@DocumentId
@FieldBridge(impl=ItemIdBridge.class)
<span class="code-keyword" style="color: #000091">public</span> ItemId getId() {
<span class="code-keyword" style="color: #000091">return</span> id;
}
<span class="code-keyword" style="color: #000091">public</span> void setId(ItemId id) {
<span class="code-keyword" style="color: #000091">this</span>.id = id;
}
        
@Fields({
@Field(name=<span class="code-quote" style="color: #009100">"itemTestItemNumber"</span>,index=Index.YES, analyze=Analyze.YES, store=Store.YES, analyzer=@Analyzer(definition=<span class="code-quote" style="color: #009100">"keywordLowerCaseAnalyzer"</span>)),
@Field(name=<span class="code-quote" style="color: #009100">"itemTestItemNumberScrubbed"</span>, index=Index.YES, analyze=Analyze.YES, store=Store.NO, analyzer=@Analyzer(impl=PartNumberRemoveSpecialCharactersAnalyzer.class))
})
@Column(name=<span class="code-quote" style="color: #009100">"ITEM_NUMBER"</span>,length=80,nullable=<span class="code-keyword" style="color: #000091">false</span>,insertable=<span class="code-keyword" style="color: #000091">true</span>,updatable=<span class="code-keyword" style="color: #000091">true</span>)
<span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">String</span> getItemNumber() {
<span class="code-keyword" style="color: #000091">return</span> itemNumber;
}
<span class="code-keyword" style="color: #000091">public</span> void setItemNumber(<span class="code-object" style="color: #910091">String</span> itemNumber) {
<span class="code-keyword" style="color: #000091">this</span>.itemNumber = itemNumber;
}
        
@Column(name=<span class="code-quote" style="color: #009100">"DESCRIPTION"</span>,length=240,nullable=<span class="code-keyword" style="color: #000091">true</span>,insertable=<span class="code-keyword" style="color: #000091">true</span>,updatable=<span class="code-keyword" style="color: #000091">true</span>)
@Field(name=<span class="code-quote" style="color: #009100">"itemTestDescription"</span>, index=Index.YES, analyze=Analyze.YES, store=Store.YES)
<span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">String</span> getDescription() {
<span class="code-keyword" style="color: #000091">return</span> description;
}
<span class="code-keyword" style="color: #000091">public</span> void setDescription(<span class="code-object" style="color: #910091">String</span> description) {
<span class="code-keyword" style="color: #000091">this</span>.description = description;
}
        
@Override
<span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">int</span> hashCode() {
<span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">new</span> HashCodeBuilder(17,31)
.append(getId())
        .append(getItemNumber())
        .append(getDescription())
        .toHashCode();
}
        
@Override
<span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">boolean</span> equals(<span class="code-object" style="color: #910091">Object</span> object) {
<span class="code-keyword" style="color: #000091">if</span>(!(object <span class="code-keyword" style="color: #000091">instanceof</span> ItemTestA)) <span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">false</span>;
ItemTestA other = (ItemTestA) object;
<span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">new</span> EqualsBuilder()        
        .append(getId(), other.getId())
        .append(getItemNumber(), other.getItemNumber())
        .append(getDescription(), other.getDescription())
        .isEquals();
}
}
</pre>
</div>
</div>
<div class="code panel" style="border-width: 1px;; border: 1px solid #ccc; background: #f5f5f5; font-size: 12px; line-height: 1.333; font-family: monospace; border: 1px solid #ccc; -moz-border-radius: 3px 3px 3px 3px; border-radius: 3px 3px 3px 3px; margin: 9px 0">
<div class="codeHeader panelHeader" style="border-bottom-width: 1px;; border-bottom: 1px solid #ccc; padding: 9px 12px">
<b>ItemIdBridge.java</b>
</div>
<div class="codeContent panelContent" style="padding: 9px 12px">
<pre class="code-java" style="margin: 10px 0 0 0; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal"><span class="code-keyword" style="color: #000091">package</span> com.setech.hibernate.search.bridge;
<span class="code-keyword" style="color: #000091">import</span> org.hibernate.search.bridge.TwoWayStringBridge;
<span class="code-keyword" style="color: #000091">import</span> com.setech.dw.inventory.domain.ItemId;
<span class="code-keyword" style="color: #000091">public</span> class ItemIdBridge <span class="code-keyword" style="color: #000091">implements</span> TwoWayStringBridge
{
        /**
         * Converts the object representation of a field into the
         * string equivalent <span class="code-keyword" style="color: #000091">for</span> the Hibernate Search module.
         *
         * @param object
         * @<span class="code-keyword" style="color: #000091">return</span> string representation of the object
         */
        @Override
        <span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">String</span> objectToString(<span class="code-object" style="color: #910091">Object</span> object) {
                <span class="code-object" style="color: #910091">String</span> result = <span class="code-keyword" style="color: #000091">null</span>;
                <span class="code-keyword" style="color: #000091">if</span>(object <span class="code-keyword" style="color: #000091">instanceof</span> ItemId) {
                        ItemId id = (ItemId) object;
                        <span class="code-object" style="color: #910091">System</span>.out.println(<span class="code-quote" style="color: #009100">"objectoString("</span> + id.getItemId() + <span class="code-quote" style="color: #009100">","</span> + id.getPlantId() + <span class="code-quote" style="color: #009100">")"</span>);
                        <span class="code-keyword" style="color: #000091">return</span> <span class="code-object" style="color: #910091">String</span>.format(<span class="code-quote" style="color: #009100">"%d_%d"</span>, id.getItemId(), id.getPlantId());
                        /*
                        StringBuilder sb = <span class="code-keyword" style="color: #000091">new</span> StringBuilder();
                        sb.append(id.getItemId() + <span class="code-quote" style="color: #009100">"_"</span>);
                        sb.append(id.getPlantId());
                        result = sb.toString();
                        */
                }
                <span class="code-keyword" style="color: #000091">return</span> result;
        }
        /**
         * Converts the string representation used by the Hibernate
         * Search module back into the object representation.
         */
        @Override
        <span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">Object</span> stringToObject(<span class="code-object" style="color: #910091">String</span> object) {
                <span class="code-object" style="color: #910091">System</span>.out.println(<span class="code-quote" style="color: #009100">"stringToObject("</span> + object + <span class="code-quote" style="color: #009100">")"</span>);
<span class="code-comment" style="color: #808080">// per sanne, there are more appropriate ways to <span class="code-keyword" style="color: #000091; color: #808080">do</span> <span class="code-keyword" style="color: #000091; color: #808080">this</span> that are more efficient
</span> <span class="code-comment" style="color: #808080">// TODO: use more efficient mechanism
</span>                <span class="code-object" style="color: #910091">String</span> fields[] = object.split(<span class="code-quote" style="color: #009100">"_"</span>);
                ItemId id = <span class="code-keyword" style="color: #000091">new</span> ItemId();
                id.setItemId(<span class="code-object" style="color: #910091">Long</span>.parseLong(fields[0]));
                id.setPlantId(<span class="code-object" style="color: #910091">Long</span>.parseLong(fields[1]));
                <span class="code-keyword" style="color: #000091">return</span> id;
        }
}
</pre>
</div>
</div>
<p style="margin: 10px 0 0 0">I first created the two entitiy objects <tt>ItemTest</tt> and <tt>ItemTestA</tt> because I didn't want to muck with our existing entity <tt>Item</tt> by removing any mappings and such and I wanted to also test whether the wider table versus a more narrow table made a difference. So I decided to build these two items and test with them.</p>
<p style="margin: 10px 0 0 0">At first I tested with <tt>ItemTest</tt> where we were not using a composite key. Using this object, the <tt>ftQuery.list()</tt> invocation was only several milliseconds in length for a page size of 250 records. This was using both the jTDS as well as the Microsoft SQL JDBC4 drivers. </p>
<p style="margin: 10px 0 0 0">The next test was where I used a composite key scenario, <tt>ItemTestA</tt>. In this test, I got the exact same stall in the <tt>ftQuery.list()</tt> invocation as I saw when using our stock <tt>Item</tt> entity class. Rather than the stall being around rows 119/120, this class appears to have a stall around rows 178/179.</p>
<p style="margin: 10px 0 0 0">Here is the DAO search method I am using for a simple fetch page blocks for an entity with a given size. </p>
<div class="code panel" style="border-width: 1px;; border: 1px solid #ccc; background: #f5f5f5; font-size: 12px; line-height: 1.333; font-family: monospace; border: 1px solid #ccc; -moz-border-radius: 3px 3px 3px 3px; border-radius: 3px 3px 3px 3px; margin: 9px 0">
<div class="codeContent panelContent" style="padding: 9px 12px">
<pre class="code-java" style="margin: 10px 0 0 0; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal"><span class="code-keyword" style="color: #000091">public</span> void doTestSearch(<span class="code-object" style="color: #910091">int</span> pageNumber, <span class="code-object" style="color: #910091">int</span> pageSize, <span class="code-object" style="color: #910091">Class</span><?> clazz) {
Level logLevel = setHibernateLogLevel(Level.DEBUG);
FullTextSession ftSession = Search.getFullTextSession(getSession());
BooleanQuery query = <span class="code-keyword" style="color: #000091">new</span> BooleanQuery();
query.add(<span class="code-keyword" style="color: #000091">new</span> TermQuery(<span class="code-keyword" style="color: #000091">new</span> Term(<span class="code-quote" style="color: #009100">"_hibernate_class"</span>, clazz.getName())), Occur.MUST);
FullTextQuery ftQuery = ftSession.createFullTextQuery(query, clazz);
                
ftQuery.setFirstResult((pageNumber-1) * pageSize).setMaxResults(pageSize);
                
<span class="code-object" style="color: #910091">int</span> totalHits = ftQuery.getResultSize();
log.info(<span class="code-quote" style="color: #009100">"Total hits: "</span> + totalHits);
                
List<?> results = ftQuery.list();
log.info(<span class="code-quote" style="color: #009100">"results fetched"</span>);
                
setHibernateLogLevel(logLevel);
}
</pre>
</div>
</div>
<p style="margin: 10px 0 0 0">As seen below, you can see where the stall happens when the Loader tries to fetch row 179. This <tt>ItemTestA</tt> table has roughly 275,000 rows in it and it doesn't matter whether I specify page 1 or page 100, the stall happens at the same exact point.</p>
<div class="code panel" style="border-width: 1px;; border: 1px solid #ccc; background: #f5f5f5; font-size: 12px; line-height: 1.333; font-family: monospace; border: 1px solid #ccc; -moz-border-radius: 3px 3px 3px 3px; border-radius: 3px 3px 3px 3px; margin: 9px 0">
<div class="codeContent panelContent" style="padding: 9px 12px">
<pre class="code-java" style="margin: 10px 0 0 0; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal">2013-07-19 12:06:49,245 DEBUG [org.hibernate.loader.Loader]: Result row: EntityKey[com.setech.dw.inventory.domain.ItemTestA#component[itemId,plantId]{plantId=6, itemId=251}]
2013-07-19 12:06:49,245 DEBUG [org.hibernate.loader.Loader]: Result set row: 178
2013-07-19 12:06:49,245 DEBUG [org.hibernate.loader.Loader]: Result row: EntityKey[com.setech.dw.inventory.domain.ItemTestA#component[itemId,plantId]{plantId=6, itemId=252}]
2013-07-19 12:06:55,468 DEBUG [org.hibernate.loader.Loader]: Result set row: 179
2013-07-19 12:06:55,468 DEBUG [org.hibernate.loader.Loader]: Result row: EntityKey[com.setech.dw.inventory.domain.ItemTestA#component[itemId,plantId]{plantId=6, itemId=253}]
2013-07-19 12:06:55,468 DEBUG [org.hibernate.loader.Loader]: Result set row: 180
</pre>
</div>
</div>
<p style="margin: 10px 0 0 0">Sanne requested that I provide the complete SQL that gets executed. I've attached the complete hibernate debug log from when this method gets executed for <tt>ItemTestA</tt> so you can see the SQL and other debugging outputs.</p>
<p style="margin: 10px 0 0 0">I could be wrong, but this seems to be something around using composite keys that is creating this bottleneck. Ideas?</p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="email-content-main mobile-expand " style="padding: 0px; border-collapse: collapse; border-left: 1px solid #ccc; border-right: 1px solid #ccc; border-top: 0; border-bottom: 0; padding: 0 15px 15px 16px; background-color: #fff">
<table id="page-title-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tr>
<td id="page-title-pattern-first-line" style="padding: 0px; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; padding-top: 16px"> <a href="https://hibernate.atlassian.net/browse/HSEARCH" style="color: #3b73af; text-decoration: none">Hibernate Search</a> / <a href="https://hibernate.atlassian.net/browse/HSEARCH-1367" style="color: #3b73af; text-decoration: none"><img src="https://hibernate.atlassian.net/images/icons/issuetypes/bug.png" height="16" width="16" border="0" align="absmiddle" alt="Bug" /></a> <a href="https://hibernate.atlassian.net/browse/HSEARCH-1367" style="color: #3b73af; text-decoration: none">HSEARCH-1367</a>
</td>
</tr>
<tr>
<td style="vertical-align: top;; padding: 0px; border-collapse: collapse; padding-right: 5px; font-size: 20px; line-height: 30px; mso-line-height-rule: exactly" id="page-title-pattern-header-container"> <span id="page-title-pattern-header" style="font-family: Arial, sans-serif; padding: 0; font-size: 20px; line-height: 30px; mso-text-raise: 2px; mso-line-height-rule: exactly; vertical-align: middle"> <a href="https://hibernate.atlassian.net/browse/HSEARCH-1367" style="color: #3b73af; text-decoration: none">FullTextQuery with max results of 250 takes considerable time to load entities</a> </span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="email-content-main mobile-expand " style="padding: 0px; border-collapse: collapse; border-left: 1px solid #ccc; border-right: 1px solid #ccc; border-top: 0; border-bottom: 0; padding: 0 15px 15px 16px; background-color: #fff">
<table id="actions-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px">
<tr>
<td id="actions-pattern-container" valign="middle" style="padding: 0px; border-collapse: collapse; padding: 0 0 0 24px; vertical-align: middle; padding-left: 0px">
<table align="left" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tr>
<td class="actions-pattern-action-icon-container" style="padding: 0px; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 0px; vertical-align: middle"> <a href="https://hibernate.atlassian.net/browse/HSEARCH-1367#add-comment" target="_blank" title="{getText($action.text)}" style="color: #3b73af; text-decoration: none"> <img class="actions-pattern-action-icon-image" src="https://hibernate.atlassian.net/images/mail/comment-icon.png" alt="Add Comment" title="{Add Comment}-icon" height="16" width="16" border="0" style="vertical-align: middle" /> </a>
</td>
<td class="actions-pattern-action-text-container" style="padding: 0px; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 4px; padding-left: 5px"> <a href="https://hibernate.atlassian.net/browse/HSEARCH-1367#add-comment" target="_blank" title="Add Comment" style="color: #3b73af; text-decoration: none">Add Comment</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<!-- there needs to be content in the cell for it to render in some clients -->
<tr>
<td class="email-content-rounded-bottom mobile-expand" style="padding: 0px; border-collapse: collapse; color: #fff; padding: 0 15px 0 16px; height: 5px; line-height: 5px; background-color: #fff; border-top: 0; border-left: 1px solid #ccc; border-bottom: 1px solid #ccc; border-right: 1px solid #ccc; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; mso-line-height-rule: exactly">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td id="footer-pattern" style="padding: 0px; border-collapse: collapse; padding: 12px 20px">
<table id="footer-pattern-container" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tr>
<td id="footer-pattern-text" class="mobile-resize-text" width="100%" style="padding: 0px; border-collapse: collapse; color: #999; font-size: 12px; line-height: 18px; font-family: Arial, sans-serif; mso-line-height-rule: exactly; mso-text-raise: 2px">
This message is automatically generated by JIRA.<br /> If you think it was sent incorrectly, please contact your JIRA administrators<br /> For more information on JIRA, see: <a style="color:#6c797f;; color: #3b73af; text-decoration: none" href="http://www.atlassian.com/software/jira">http://www.atlassian.com/software/jira</a>
</td>
<td id="footer-pattern-logo-desktop-container" valign="top" style="padding: 0px; border-collapse: collapse; padding-left: 20px; vertical-align: top">
<table style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tr>
<td id="footer-pattern-logo-desktop-padding" style="padding: 0px; border-collapse: collapse; padding-top: 3px"> <img id="footer-pattern-logo-desktop" src="https://hibernate.atlassian.net/images/mail/footer-desktop-logo.png" alt="JIRA logo" title="JIRA logo" width="92" height="36" class="image_fix" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>