81,122
社区成员




public List<B> search(ASObject arg){
ADAO ad = new ADAO();
Integer id = (Integer)arg.get("id");
A a = ad.findById(id);
Set<B> b = a.getB();
......
}
public List<ExpertInfo> searchByProfession(List<ASObject> professions){
ProfessionCategoryDAO pcd = new ProfessionCategoryDAO();
List<ExpertInfo> experts = new ArrayList<ExpertInfo>();
experts.add(new ExpertInfo());
for(ASObject professionAS:professions){
Integer id = (Integer)professionAS.get("id");
ProfessionCategory pc = pcd.findById(id);
Set<ExpertProfession> prfSet = pc.getExpertProfessions();
if(prfSet!=null){
Iterator<ExpertProfession> it = prfSet.iterator();
while(it.hasNext()){
ExpertInfo expert = it.next().getId().getExpertInfo();
if(expert!=null && experts.contains(expert)==false){
experts.add(expert);
}
}
}
}
experts.remove(0);
return experts;
}
其中prfSet总为null,而根据类定义,它应该是已经被初始化过的。
回复楼上:
每个id都能取到其对应的对象,数据库里也有相应的行,这个没有问题。
public abstract class AbstractExpertInfo implements java.io.Serializable {
// Fields
private Integer id;
private String name;
......
private Set<ExpertProfession> expertProfessions = new HashSet<ExpertProfession>(0);
private Set<Account> accounts = new HashSet<Account>(0);
......
}
B类:
public abstract class AbstractProfessionCategory implements java.io.Serializable {
// Fields
private Integer id;
private String firstnum;
......
private Set<ExpertProfession> expertProfessions = new HashSet<ExpertProfession>(0);
......
}
AB的组合id类:
public abstract class AbstractExpertProfessionId implements java.io.Serializable {
// Fields
private ExpertInfo expertInfo;
private ProfessionCategory professionCategory;
......
}
AB类:
public abstract class AbstractExpertProfession implements java.io.Serializable {
// Fields
private ExpertProfessionId id;
private Short majorProfession;
......
}
<hibernate-mapping>
<class name="pojo.ExpertInfo" table="ep_info" catalog="expertdb">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="native"></generator>
</id>
<property name="name" type="java.lang.String">
<column name="name" length="45" />
</property>
......
<set name="expertProfessions" inverse="true" lazy="extra">
<key>
<column name="ep_info_id" not-null="true" />
</key>
<one-to-many class="pojo.ExpertProfession" />
</set>
<set name="accounts" inverse="true" lazy="extra">
<key>
<column name="ep_info_id" not-null="true" />
</key>
<one-to-many class="pojo.Account" />
</set>
</class>
</hibernate-mapping>
b表->B类的映射文件:
<hibernate-mapping>
<class name="pojo.ProfessionCategory" table="pf_category" catalog="expertdb">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="native"></generator>
</id>
<property name="firstnum" type="java.lang.String">
<column name="firstnum" length="45" />
</property>
......
<set name="expertProfessions" inverse="true" lazy="extra">
<key>
<column name="pf_category_id" not-null="true" />
</key>
<one-to-many class="pojo.ExpertProfession" />
</set>
</class>
</hibernate-mapping>
ab表->AB类的映射文件:
<hibernate-mapping>
<class name="pojo.ExpertProfession" table="ep_info_has_pf_category" catalog="expertdb">
<composite-id name="id" class="pojo.ExpertProfessionId">
<key-many-to-one name="expertInfo" class="pojo.ExpertInfo">
<column name="ep_info_id" />
</key-many-to-one>
<key-many-to-one name="professionCategory" class="pojo.ProfessionCategory">
<column name="pf_category_id" />
</key-many-to-one>
</composite-id>
<property name="majorProfession" type="java.lang.Short">
<column name="major_profession"/>
</property>
</class>
</hibernate-mapping>
public List<B> search(ASObject arg){
ADAO ad = new ADAO();
Integer id = (Integer)arg.get("id");
A a = ad.findById(id);
Set<AB> ab = a.getAB();
......
}
其它描述大致不变,即对象ab总为null