Some time ago has written an article about Compass, I believe that we have a certain understanding of the compass
Since the most recent project involves site search and is based on the JPA annotation form and has been on the web for a long time, there are few examples of JPA integration compass, some of which are xml-based, and very few based on annotations, There is no way only to Compass's official website download English documents themselves research, spent the afternoon to debug out, integrated into the project!
Here to share with you, I hope you can take some detours less!
1. Go to the official website to download the Compass jar package, I use the 2.1 version
http://www.compass-project.org/
Productinfo.java
Java code
@Entity
@Searchable
public class ProductInfo implements serializable{
private static final long serialversionuid = -8860864584425256200l;
private Integer ID;
/** Item Number **/
private String Code;
/** Product Name **/
private String name;
/** Product Type **/
private ProductType type;
/** Product Style **/
private set<productstyle> styles = new hashset<productstyle> ();
public ProductInfo () {}
@OneToMany (Cascade={cascadetype.remove,cascadetype.persist}, mappedby= "Product", Fetch=fetchtype.eager)
@OrderBy ("Visible desc, id ASC")
@SearchableReference
public set<productstyle> Getstyles () {
return styles;
}
public void Setstyles (set<productstyle> styles) {
this.styles = styles;
}
@Id @GeneratedValue
@SearchableId
public Integer getId () {
return ID;
}
public void setId (Integer id) {
this.id = ID;
}
@Column (length=30)
@SearchableProperty (index = index.tokenized, store = store.yes)
public String GetCode () {
return code;
}
public void Setcode (String code) {
This.code = code;
}
@Column (Length=50,nullable=false)
@SearchableProperty (index = index.tokenized, store = store.yes)
public String GetName () {
return name;
}
public void SetName (String name) {
this.name = name;
}
@ManyToOne (Cascade=cascadetype.refresh,optional=false)
@JoinColumn (name= "typeID")
@SearchableReference
public ProductType GetType () {
return type;
}
public void SetType (ProductType type) {
this.type = type;
}
@Override
public int hashcode () {
final int prime = 31;
int result = 1;
result = Prime * result + ((id = = null) 0:id.hashcode ());
return result;
}
@Override
public boolean equals (Object obj) {
if (this = = obj)
return true;
if (obj = null)
return false;
if (getclass ()!= obj.getclass ())
return false;
final ProductInfo other = (productinfo) obj;
if (id = = NULL) {
if (other.id!= null)
return false;
} else if (!id.equals (other.id))
return false;
return true;
}
}