petDiary映射文件里加入:
<many-to-one name="petInfo"/>
petInfo的映射文件:
<set name="petDiary">
<key column="pdid"/>
<one-to-many class="com.moon.model.PetInfo"/>
</set>
<many-to-one name="petInfo"/>
petInfo的映射文件:
<set name="petDiary">
<key column="pdid"/>
<one-to-many class="com.moon.model.PetInfo"/>
</set>
解决方案 »
- EAO与DAO 的区别是什么?
- 求教自己编写的简单留言系统为什么会注册失败问题
- 有人用ectable么?
- 请教下hibernate的几个问题
- org.hibernate.exception.SQLGrammarException: could not execute query
- 谁能告诉我oscache 中的cache标签的各个属性是什么意思啊??急。。。
- 哪种 Spring 的 JAR 包适合我们
- java 调用 .net的webservice问题
- 关于J2EE的问题,急急急???
- 重复数据插入问题
- 请问 不经J2SE,直接进军J2EE可以吗?J2EE有哪些较好入门材料 谢谢
- oracle问题
<key>
<column name="diary_pet_id" />
</key>
<one-to-many class="com.hch.hib.pojo.PetDiary" />
</set>但是查询的时候就是查不出来petInfo的信息
<key>
<column name="diary_pet_id" />
</key>
<one-to-many class="com.hch.hib.pojo.PetInfo" />
</set>
那么在petDiary的BEAN中就有属性 private PetInfo petInfo;生成get set方法
String hql="select * from petDiary where PetDiary.id='"+id+"'";
List list = this.find(hql);//执行查询
PetInfo petInfo = list.get(0).getPetInfo();//返回PetInfo对象
petInfo就是你要获取的宠物信息了.以上只是给楼主一个获取信息的方法,没有严格的去写,只是个思路.
在你的日记对象中 应该有个属性叫宠物 然后get 那个宠物就有信息了
private Set diary=new HashSet();
在PetDiary中时候有PetInfo 的对象
private PetInfo pet=new PetInfo ();如果都有的话 再看报什么异常 异常:org.hibernate.LazyInitializationException
描述:failed to lazily initialize a collection of role: com.pet.entity.Pet.diary, no session or session was closed
原因:配置有问题,把hibernate里面的那个:.hbm.xml文件中,配置lazy=false; 这是由于lazy而产生的错误,
<set name="diary" lazy="false">
<key column="diary_pet_id" />
<one-to-many class="com.hch.hib.pojo.PetDiary"/>
</set> 异常:org.hibernate.exception.SQLGrammarException
描述:could not initialize a collection: [com.pet.entity.Pet.diary#1]
原因:Sql语句有误,配置文件中的列名错 你再把SQL语句输出来下 看看有什么错误