Category.jsp public class Category { private int id; //类别编号 private String name; //类别名称 private Set meds; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Set getMeds() { return meds; } public void setMeds(Set meds) { this.meds = meds; } }Info.java public class Info {
private int id; //id号 private String title; //标题 private Category cates; //类别 public int getId() { return id; } public void setId(int id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public int getCategoryId() { return categoryId; } public void setCategoryId(int categoryId) { this.categoryId = categoryId; } public Category getCates() { return cates; } public void setCates(Category cates) { this.cates = cates; }
}是这个吗?
不好意思 Info.java还有 private int categoryId;
这应该没关联上吧 ,不知道你的Category类中的meds什么意思?????? 1、第一步 public class Category { private int id; //类别编号 private String name; //类别名称 private Set meds; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Set getMeds() { return meds; } public void setMeds(Set meds) { this.meds = meds; } } 把private Set meds换成private Set infos; 2、第二步 :把 private int categoryId;去掉。 3、 <set name="meds" inverse="true" cascade="all" order-by="categoryId"> <key column="categoryId"/> <one-to-many class="Info"/> </set> 改成 <set name="infos" inverse="true" cascade="all" > <key column="categoryId"/> <one-to-many class="Info"/> </set> 4、把: <!-- 与类别的多对一关系 --> <many-to-one name="cates" column="categoryId" cascade="save-update" lazy="proxy"/> 改成: <!-- 与类别的多对一关系 --> <many-to-one name="cates" column="categoryId" class="Category" cascade="save-update" lazy="proxy"/> 5、根据CategoryId查询 info吧?hql=" from Category c where c.categoryId="+id;//查询结果Category对象,他不是有infos集合嘛,这样不就查出来了吗?
public class Category {
private int id; //类别编号
private String name; //类别名称
private Set meds;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Set getMeds() {
return meds;
}
public void setMeds(Set meds) {
this.meds = meds;
}
}Info.java
public class Info {
private int id; //id号
private String title; //标题
private Category cates; //类别
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
} public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getCategoryId() {
return categoryId;
}
public void setCategoryId(int categoryId) {
this.categoryId = categoryId;
} public Category getCates() {
return cates;
}
public void setCates(Category cates) {
this.cates = cates;
}
}是这个吗?
private int categoryId;
1、第一步
public class Category {
private int id; //类别编号
private String name; //类别名称
private Set meds;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Set getMeds() {
return meds;
}
public void setMeds(Set meds) {
this.meds = meds;
}
}
把private Set meds换成private Set infos;
2、第二步 :把 private int categoryId;去掉。
3、 <set name="meds" inverse="true" cascade="all" order-by="categoryId">
<key column="categoryId"/>
<one-to-many class="Info"/>
</set> 改成 <set name="infos" inverse="true" cascade="all" >
<key column="categoryId"/>
<one-to-many class="Info"/>
</set>
4、把: <!-- 与类别的多对一关系 -->
<many-to-one name="cates" column="categoryId" cascade="save-update" lazy="proxy"/>
改成: <!-- 与类别的多对一关系 -->
<many-to-one name="cates" column="categoryId" class="Category" cascade="save-update" lazy="proxy"/>
5、根据CategoryId查询 info吧?hql=" from Category c where c.categoryId="+id;//查询结果Category对象,他不是有infos集合嘛,这样不就查出来了吗?