为什么我对复合类型用@SearchableComponent注释,也对该类@Searchable(root=false)做了注释,
ProductInfo.java@Entity
@Searchable//将该实体标示为需要搜索的实体
public class ProductInfo implements Serializable{
/** 产品id **/
private int id;
/** 产品名称 **/
private String name;
/** 品牌 **/
private Brand brand; @Id @GeneratedValue
@SearchableId
public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} @Column(length=20,nullable=false)
@SearchableProperty(boost=2,name="productName")
public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
@ManyToOne(optional=true,cascade=CascadeType.REFRESH)
@JoinColumn(name="brandid")
@SearchableComponent
public Brand getBrand() {
return brand;
} public void setBrand(Brand brand) {
this.brand = brand;
}}Brand.java @Entity
@Searchable(root=false)//代表不是独立搜索实体,只是其他搜索实体的一部分
public class Brand implements Serializable{
private static final long serialVersionUID = 8500461881015169737L; /** 品牌ID **/
private int id;
/** 品牌名称 **/
private String name; @Id @GeneratedValue
@SearchableProperty(index=Index.NO,store=Store.YES,name="brandid")
public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} @Column(length=20,nullable=false)
@SearchableProperty(index=Index.NOT_ANALYZED,store=Store.YES,name="brandName")
public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}通过
CompassHits hits = session.find(keyword);
for(int i = firstResult; i < length; i++) {
ProductInfo product = (ProductInfo)hits.data(i);
System.out.println(product.getBrand().getId());//这里就会报空指针,则就说明brand为null,为什么我映射了关系还是不行了,请大侠解释下啊,这是什么原因,怎么解决
}
ProductInfo.java@Entity
@Searchable//将该实体标示为需要搜索的实体
public class ProductInfo implements Serializable{
/** 产品id **/
private int id;
/** 产品名称 **/
private String name;
/** 品牌 **/
private Brand brand; @Id @GeneratedValue
@SearchableId
public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} @Column(length=20,nullable=false)
@SearchableProperty(boost=2,name="productName")
public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
@ManyToOne(optional=true,cascade=CascadeType.REFRESH)
@JoinColumn(name="brandid")
@SearchableComponent
public Brand getBrand() {
return brand;
} public void setBrand(Brand brand) {
this.brand = brand;
}}Brand.java @Entity
@Searchable(root=false)//代表不是独立搜索实体,只是其他搜索实体的一部分
public class Brand implements Serializable{
private static final long serialVersionUID = 8500461881015169737L; /** 品牌ID **/
private int id;
/** 品牌名称 **/
private String name; @Id @GeneratedValue
@SearchableProperty(index=Index.NO,store=Store.YES,name="brandid")
public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} @Column(length=20,nullable=false)
@SearchableProperty(index=Index.NOT_ANALYZED,store=Store.YES,name="brandName")
public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}通过
CompassHits hits = session.find(keyword);
for(int i = firstResult; i < length; i++) {
ProductInfo product = (ProductInfo)hits.data(i);
System.out.println(product.getBrand().getId());//这里就会报空指针,则就说明brand为null,为什么我映射了关系还是不行了,请大侠解释下啊,这是什么原因,怎么解决
}
解决方案 »
- 2个WEB开发中的小问题,请大家指教下。
- 为什么我的jsp每次用tomcat运行后都不能加到webapps里面
- 大家讨论下开源java软件的源代码学习研究利用捷径吧
- 关于session的问题
- TreeSet的higher和lower方法报NoSuchMethodError错!
- 有人用过SVF吗?做帐票的!求救啊
- System.getProperty不起作用?晕死了
- 大家来看看这是什么错误!!
- tomcat和apache整合以后,还能使用servlet吗?
- 最后的34分!!请教一个关于javascript中如何通过循环动态生成一个select
- 关于自己编写抛出异常或者是容错处理的问题
- 关于正则表达式
但是我的确是有品牌名称为什么获取不到了