Topic: 第一次试验hibernate的one-to-many,不成功 |
Print this page |
1.第一次试验hibernate的one-to-many,不成功 | Copy to clipboard |
Posted by: guorui_wh Posted on: 2004-11-15 11:20 我的环境是spring+hibernate 例子是Forum和Topic的one to many关系,是这样配置的 Forum: <set name="topics" lazy="false" outer-join="auto" inverse="true" cascade="all" sort="unsorted" table="t_bbs_topic"> <key column="forum_id"></key> <one-to-many class="com.bbs.po.hibernatepo.TbbsTopic" /> </set> Topic: <many-to-one name="forum" class="com.bbs.po.hibernatepo.TbbsForum" column="forum_id" outer-join="auto" cascade="none" access="property" update="true" insert="true" not-null="true"> </many-to-one> Test code : TbbsForum forum = findById(1); System.out.println("Name:" + forum.getName()); TbbsTopic topic = new TbbsTopic(); topic.setContent("test"); topic.setCreateDate(Function.getSystime()); topic.setCreateUser("guorui_wh"); topic.setId(new Integer(234)); topic.setLastReplyDate(Function.getSystime()); topic.setLastReplyUser("guorui_wh"); topic.setReplyCount(0); topic.setShowFlag(true); topic.setTitle("asdfasdf"); topic.setTopFlag(true); topic.setForum(forum); forum.getTopics().add(topic); getHibernateTemplate().save(forum); |
2.Re:第一次试验hibernate的one-to-many,不成功 [Re: guorui_wh] | Copy to clipboard |
Posted by: guorui_wh Posted on: 2004-11-15 11:22 Exception info: Hibernate: insert into t_bbs_forum (name, master, create_date, create_user, remark, id) values (?, ?, ?, ?, ?, ?) java.sql.BatchUpdateException: Invalid argument value: Duplicate entry '1' for key 1 为什么会是插入到forum 中去呢,我是按照夏昕的hibernate开发指南上一步一步作的 |
3.Re:第一次试验hibernate的one-to-many,不成功 [Re: guorui_wh] | Copy to clipboard |
Posted by: yipsilon Posted on: 2004-12-05 20:45 Topic的key是不是原始类型的? 像int或long这样的? 如果是, 使用Integer或Long替代.... |
4.Re:第一次试验hibernate的one-to-many,不成功 [Re: guorui_wh] | Copy to clipboard |
Posted by: wenyuqiu Posted on: 2004-12-05 23:14 有某个主键重复了吧自己再仔细查查看, |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |