OK, problem is not solved. I have still the same issue. :-(
This is my hibernate-mapping file:
Code:
<class name="de.bauerlive.ngshop.data.ProductText" table="product_text">
<cache usage="nonstrict-read-write"/>
<composite-id class="de.bauerlive.ngshop.data.identifiers.ProductText_Id" name="id">
<key-property column="MANDT" length="4" name="mandt" type="string"/>
<key-property column="LANG" length="2" name="lang" type="string"/>
<key-property column="PRODID" length="40" name="prodid" type="string"/>
</composite-id>
<property column="STEXT" length="80" name="stext" type="string"/>
<property name="ltext" type="text"/>
<many-to-one class="de.bauerlive.ngshop.data.Product" fetch="select" insert="false" name="product" update="false">
<column length="4" name="mandt" not-null="true"/>
<column length="40" name="prodid" not-null="true"/>
</many-to-one>
</class>
<class name="de.bauerlive.ngshop.data.Product" table="product">
<cache usage="nonstrict-read-write"/>
<composite-id class="de.bauerlive.ngshop.data.identifiers.Product_Id" name="id">
<key-property column="MANDT" length="4" name="mandt" type="string"/>
<key-property column="PRODID" length="40" name="prodid" type="string"/>
</composite-id>
<property column="DATBI" name="datbi" type="timestamp"/>
<property column="DATAB" name="datab" type="timestamp"/>
<property column="FOLGEPROD" length="40" name="folgeprod" type="string"/>
...
</class>
Here are the two Id-component classes:
Code:
@Analyzer(impl=de.bauerlive.ngshop.logic.BLNGAnalyzer.class)
public class ProductText_Id implements Serializable {
private static final long serialVersionUID = 8194101847993970529L;
@Field(index=Index.UN_TOKENIZED, store=Store.YES)
protected String mandt;
@Field(index=Index.UN_TOKENIZED,store=Store.YES)
protected String lang;
@Field(index=Index.UN_TOKENIZED, store=Store.YES, boost=@Boost(2f))
protected String prodid;
@Override
public String toString() {
return Integer.toString(this.hashCode());
}
/**
* Get the value of prodid
*
* @return the value of prodid
*/
public String getProdid() {
return prodid;
}
/**
* Set the value of prodid
*
* @param prodid new value of prodid
*/
public void setProdid(String prodid) {
this.prodid = prodid;
}
/**
* Get the value of lang
*
* @return the value of lang
*/
public String getLang() {
return lang;
}
/**
* Set the value of lang
*
* @param lang new value of lang
*/
public void setLang(String lang) {
this.lang = lang;
}
/**
* Get the value of mandt
*
* @return the value of mandt
*/
public String getMandt() {
return mandt;
}
/**
* Set the value of mandt
*
* @param mandt new value of mandt
*/
public void setMandt(String mandt) {
this.mandt = mandt;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final ProductText_Id other = (ProductText_Id) obj;
if ((this.mandt == null) ? (other.mandt != null) : !this.mandt.equals(other.mandt)) {
return false;
}
if ((this.lang == null) ? (other.lang != null) : !this.lang.equals(other.lang)) {
return false;
}
if ((this.prodid == null) ? (other.prodid != null) : !this.prodid.equals(other.prodid)) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 3;
hash = 19 * hash + (this.mandt != null ? this.mandt.hashCode() : 0);
hash = 19 * hash + (this.lang != null ? this.lang.hashCode() : 0);
hash = 19 * hash + (this.prodid != null ? this.prodid.hashCode() : 0);
return hash;
}
}
and
Code:
public class Product_Id implements Serializable {
private static final long serialVersionUID = -1647812012628341082L;
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Product_Id other = (Product_Id) obj;
if ((this.mandt == null) ? (other.mandt != null) : !this.mandt.equals(other.mandt)) {
return false;
}
if ((this.prodid == null) ? (other.prodid != null) : !this.prodid.equals(other.prodid)) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 7;
hash = 89 * hash + (this.mandt != null ? this.mandt.hashCode() : 0);
hash = 89 * hash + (this.prodid != null ? this.prodid.hashCode() : 0);
return hash;
}
protected String mandt;
protected String prodid;
/**
* Get the value of prodid
*
* @return the value of prodid
*/
public String getProdid() {
return prodid;
}
/**
* Set the value of prodid
*
* @param prodid new value of prodid
*/
public void setProdid(String prodid) {
this.prodid = prodid;
}
/**
* Get the value of mandt
*
* @return the value of mandt
*/
public String getMandt() {
return mandt;
}
/**
* Set the value of mandt
*
* @param mandt new value of mandt
*/
public void setMandt(String mandt) {
this.mandt = mandt;
}
}
And here the field bridge:
Code:
public class ProductTextBridge implements TwoWayFieldBridge {
public Object get(String fieldName, Document doc) {
ProductText_Id questionPK = new ProductText_Id();
Field field = null;
field = doc.getField(fieldName + ".mandt");
questionPK.setMandt(field.stringValue());
field = doc.getField(fieldName + ".prodid");
questionPK.setProdid(field.stringValue());
field = doc.getField(fieldName + ".lang");
questionPK.setLang(field.stringValue());
return questionPK;
}
public String objectToString(Object obj) {
ProductText_Id questionPK = (ProductText_Id) obj;
StringBuilder sb = new StringBuilder();
sb.append(questionPK.getMandt()).append(" ").append(questionPK.getLang()).append(" ").append(questionPK.getProdid());
return sb.toString();
}
public void set(String fieldName, Object obj, Document doc, Store store, Index index, Float boost) {
ProductText_Id questionPK = (ProductText_Id) obj;
Field field = new Field(fieldName + ".mandt", questionPK.getMandt(), store, index);
if (boost != null) {
field.setBoost(boost);
}
doc.add(field);
field = new Field(fieldName + ".lang", questionPK.getLang(), store, index);
if (boost != null) {
field.setBoost(boost);
}
doc.add(field);
field = new Field(fieldName + ".prodid", questionPK.getProdid(), store, index);
if (boost != null) {
field.setBoost(boost);
}
doc.add(field);
}
@Override
public void set(String arg0, Object arg1, Document arg2, LuceneOptions arg3) {
set(arg0, arg1, arg2, arg3.getStore(), arg3.getIndex(), arg3.getBoost());
}
}
and
Code:
public class ProductBridge implements TwoWayFieldBridge {
public Object get(String fieldName, Document doc) {
Product_Id questionPK = new Product_Id();
Field field = null;
field = doc.getField(fieldName + ".mandt");
questionPK.setMandt(field.stringValue());
field = doc.getField(fieldName + ".prodid");
questionPK.setProdid(field.stringValue());
return questionPK;
}
public String objectToString(Object obj) {
Product_Id questionPK = (Product_Id) obj;
StringBuilder sb = new StringBuilder();
sb.append(questionPK.getMandt()).append(" ").append(questionPK.getProdid());
return sb.toString();
}
public void set(String fieldName, Object obj, Document doc, Store store, Index index, Float boost) {
Product_Id questionPK = (Product_Id) obj;
Field field = new Field(fieldName + ".mandt", questionPK.getMandt(), store, index);
if (boost != null) {
field.setBoost(boost);
}
doc.add(field);
field = new Field(fieldName + ".prodid", questionPK.getProdid(), store, index);
if (boost != null) {
field.setBoost(boost);
}
doc.add(field);
}
@Override
public void set(String arg0, Object arg1, Document arg2, LuceneOptions arg3) {
set(arg0, arg1, arg2, arg3.getStore(), arg3.getIndex(), arg3.getBoost());
}
}
If i now search with
Code:
FullTextSession fullTextSession = Search.getFullTextSession(session);
Transaction tx = fullTextSession.beginTransaction();
Analyzer anal = new BLNGAnalyzer();
String[] fields = new String[]{"prodid", "stext", "ltext", "product.eans", "product.manufacturer_aid", "product.manufacturerName"};
MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, anal);
//QueryParser parser = new QueryParser("prodid", anal);
parser.setAllowLeadingWildcard(true);
parser.setDefaultOperator(Operator.AND);
BooleanQuery lquery = new BooleanQuery();
try {
lquery.add(parser.parse(entered), BooleanClause.Occur.MUST);
lquery.add(new TermQuery(new Term("mandt", mvh.getUser().getMandt())), BooleanClause.Occur.MUST);
lquery.add(new TermQuery(new Term("lang", mvh.getUser().getLang().toLowerCase())), BooleanClause.Occur.MUST);
lquery.add(parser.parse(catSearch), BooleanClause.Occur.MUST);
} catch (ParseException ex) {
Logger.getLogger(ProductDAO.class.getName()).log(Level.SEVERE, null, ex);
}
FullTextQuery hibQuery = fullTextSession.createFullTextQuery(lquery, ProductText.class);
hibQuery.setCacheable(true);
hibQuery.setMaxResults(aThis.getMaxResults());
hibQuery.setFirstResult(aThis.getFirstResult());
List l = hibQuery.list();
I get multiple times the SAME product (they definitely have the same values of their identifiers). I really don't get it.... :-(