compass与SSH结合使用,配置文件如下 :
<!-- SSH 集成Compass -->
<bean id="compass" class="org.compass.spring.LocalCompassBean">
<property name="classMappings">
<list>
<value>com.bean.product.ProductInfo<alue>
<value>com.bean.product.ProductType<alue>
<st>
</property>
<property name="compassSettings">
<props>
<!-- 将默认分词(一元分词)改为 Paoding分词(基于字典分词) -->
<prop key="compass.engine.analyzer.default.type">net.paoding.analysis.analyzer.PaodingAnalyzer</prop>

<!-- 指定索引文件存放的位置  -->
<prop key="compass.engine.connection">file://d:/index</prop> <!-- 指定绝对路径:file://d:/index -->
<!-- 索引文件存入在内存中(在硬盘上没有索引文件) -->
<!-- <prop key="compass.engine.connection">ram://index</prop> -->

<!-- 设置搜索关键字高亮显示 -->
<prop key="compass.engine.highlighter.default.formatter.simple.pre"><![CDATA[<font color='red'>]]></prop>
<prop key="compass.engine.highlighter.default.formatter.simple.post"><![CDATA[</font>]]></prop>

<!-- 设置Compass的事务从Spring的事务管理器获取事务,,使其与Hibernate的事务是同一事务 -->
<prop key="compass.transaction.factory">org.compass.spring.transaction.SpringSyncTransactionFactory</prop>
</props>
</property>
<property name="transactionManager" ref="transactionManager" />
</bean>  <!-- Compass GPS 自动完成索引的添加、修改、删除操作 -->
 <bean id="compassGps" class="org.compass.gps.impl.SingleCompassGps" init-method="start" destroy-method="stop">
       <property name="compass" ref ="compass"/>
       <property name="gpsDevices">
         <list>
          <!-- 设置Hibernate驱动  -->
           <ref bean="hibernateGpsDevice" />
         <st>
       </property>
     </bean>
     
     <bean id="hibernateGpsDevice" class="org.compass.spring.device.hibernate.dep.SpringHibernate3GpsDevice">
       <property name="name"><value>hibernateDevice<alue></property>
       <property name="sessionFactory"><ref local="sessionFactory" /></property>
     </bean>ProductType是ProductInfo的父类,,我设置ProductInfo为索引对象,,在PrductType的类上标注:
package com.bean.product;import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;import org.compass.annotations.Index;
import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableProperty;
/**
 * 产品类型
 * @author Administrator
 *
 */
@Entity @Searchable(root=false)
public class ProductType implements Serializable{

/**类别Id*/
private Integer typeid;
/**类别名称*/
private String name;
@GeneratedValue(strategy=GenerationType.AUTO)
@SearchableProperty(index=Index.NO)
public Integer getTypeid() {
return typeid;
}
public void setTypeid(Integer typeid) {
this.typeid = typeid;
}

@Column(length=36,nullable=false)
@SearchableProperty(index=Index.NOT_ANALYZED,name="typeName")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}ProductInfo类如下:
package com.bean.product;import java.util.Date;
import java.util.HashSet;
import java.util.Set;import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;import org.compass.annotations.Index;
import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableComponent;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;
import org.compass.annotations.Store;@Entity @Searchable //@Searchable 定义为搜索实体
public class ProductInfo {
public ProductInfo(){}

public ProductInfo(Integer id){
this.id = id;
}

/**主键*/
private Integer id;
/**产品名*/
private String name;
/**产品类型*/
private ProductType type;


@Id
@GeneratedValue @SearchableId
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}

@Column(length=50,nullable=false)
@SearchableProperty(index=Index.ANALYZED,store=Store.YES,boost=3,name="productName")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

@ManyToOne(cascade=CascadeType.REFRESH,optional=false)
@JoinColumn(name="typeid")
@SearchableComponent
public ProductType getType() {
return type;
}
public void setType(ProductType type) {
this.type = type;
}
}为什么我每次搜索产品时,搜到其类型ProductType 的typeid有值,,而类型的其它属性都为null ?