数据库设计<many-to-one>和<one-to-many>双向映射
2012-04-15 10:34
375 查看
数据库设计<many-to-one>和<one-to-many>双向映射4/14/2012-10:43:30 PM:
1、映射图书信息错了“字段write”应为”writer:”
2、org.hibernate.MappingException: Repeated column in mapping for entity: com.database.bean.Remark column:bookid (should be mapped
with insert="false"update="false")
原因:<many-to-one
name="bookinfo"
class="Bookinfo"fetch="select">
<column
name="bookid"not-null="true"></column>
</many-to-one>
<many-to-one
name="userinfo"class="Userinfo"
fetch="select">
<column
name="bookid"not-null="true"></column>
</many-to-one>
可以看到bookid出现了两次,把最上面的那个去掉即可,因为两个属性不能对应一行。哈哈,受益咯
<many-to-one>的<column
name=" "指示的是当前表的字段名。
所以肯定不能再多个<many-to-one>中重复。
3、could not fetchinitial value for increment generator?
等我把Hibernate的设置为显示Sql语句后发现执行了Hibernate: select max(id) from order就报错,说order表有问题。后来我用select max(id) from order在mysql的命定窗口,发现也报错,但是把表order表改一下名字就好了,现在都不知道怎么回事。
“could not fetchinitial value for increment generator”一般说是“increment”类设置id的时候错了,这个mysql,我用increment都没有错的。一般在SQLserver上吧。
经验:Caused by是问题的关键所在。
1、映射图书信息错了“字段write”应为”writer:”
2、org.hibernate.MappingException: Repeated column in mapping for entity: com.database.bean.Remark column:bookid (should be mapped
with insert="false"update="false")
原因:<many-to-one
name="bookinfo"
class="Bookinfo"fetch="select">
<column
name="bookid"not-null="true"></column>
</many-to-one>
<many-to-one
name="userinfo"class="Userinfo"
fetch="select">
<column
name="bookid"not-null="true"></column>
</many-to-one>
可以看到bookid出现了两次,把最上面的那个去掉即可,因为两个属性不能对应一行。哈哈,受益咯
<many-to-one>的<column
name=" "指示的是当前表的字段名。
所以肯定不能再多个<many-to-one>中重复。
3、could not fetchinitial value for increment generator?
等我把Hibernate的设置为显示Sql语句后发现执行了Hibernate: select max(id) from order就报错,说order表有问题。后来我用select max(id) from order在mysql的命定窗口,发现也报错,但是把表order表改一下名字就好了,现在都不知道怎么回事。
“could not fetchinitial value for increment generator”一般说是“increment”类设置id的时候错了,这个mysql,我用increment都没有错的。一般在SQLserver上吧。
经验:Caused by是问题的关键所在。
相关文章推荐
- <many to one>和<one to many>
- Hibernate逍遥游记-第13章 映射实体关联关系-001用外键映射一对一(<many-to-one unique="true">、<one-to-one>)
- <many-to-one>设置
- Hibernate逍遥游记-第5章映射一对多-02双向(<set>、<key>、<one-to-many>、inverse、cascade="all-delete-orphan")
- <三>重温Hibernate one to many 映射配置
- Hibernate——<one-to-many/>
- 015 一对多关联映射 双向(one-to-many)
- 一对多关联映射(双向关联)见项目:me_one_to_many2
- Hibernate逍遥游记-第5章映射一对多-01单向<many-to-one>、cascade="save-update"、lazy、TransientObjectException
- <many-to-one>和<one-to-many>
- hibernate 双向多对一 many-to-one 映射 关联查询
- hibernate many-to-many(单向和双向)--->(annotation和xml文件两种形式)
- hibernate中hbm.xml<many-to-one><one-to-many>中一些属性详解
- Hibernate 中annotations(注解开发)的@OneToMany 一对多双向关联映射后,出现的jar包冲突问题
- one-to-many双向关联映射
- hibernate注解版关联映射Many-to-One/Many-to-Many等&异常处理
- Hibernate——<many-to-one/>
- 自己总结一下关联关系映射中的OneToMany,ManyToOne,单向,双向注意的事项!ps:例子
- 020 <one-to-one>、<many-to-one>单端关联上的lazy(懒加载)属性
- Hibernate one-to-many && many-to-many 的关系映射