Spring+hibernate
来源:互联网 发布:win7开机优化 编辑:程序博客网 时间:2024/06/05 11:47
There are two varieties of one-to-one association:
-
primary key associations
-
unique foreign key associations
Primary key associations don't need an extra table column; if two rows are related by the association then the two table rows share the same primary key value. So if you want two objects to be related by a primary key association, you must make sure that they are assigned the same identifier value!
Alternatively, a foreign key with a unique constraint, from Employee to Person, may be expressed as:
<many-to-one name="person" class="Person" column="PERSON_ID" unique="true"/>有2种,主键相同/用many-to-one.
主键相同的时候不需要额外的column。如果2个表不共享一个主键,那么必须要注意,2个对象的主键必须相同!
另外出了一个问题:
分别保存关联的3个对象,在最后一个报错,大概意思是非法的将一个集合关联到2个session。找了半天,网上有说用merge()代替update()即解决了该问题。经过讨论分析,根本的原因是OpenSessionInViewFilter的singleton设置为false。
文档:
If set to false, each data access operation or transaction will use its own session (like without Open Session in View).
Alternatively, turn this filter into deferred close mode, by specifying "singleSession"="false": It will not use a single session per request then, but rather let each data access operation or transaction use its own session (like without Open Session in View). Each of those sessions will be registered for deferred close, though, actually processed at request completion.
A single session per request allows for most efficient first-level caching, but can cause side effects, for example on saveOrUpdate or if continuing after a rolled-back transaction. The deferred close strategy is as safe as no Open Session in View in that respect, while still allowing for lazy loading in views (but not providing a first-level cache for the entire request).
- Spring + Hibernate
- Spring + Hibernate
- spring+hibernate
- Spring + Hibernate
- hibernate+spring
- Spring+hibernate
- hibernate+spring
- Spring+Hibernate
- spring+hibernate
- spring-hibernate
- hibernate+spring
- spring hibernate
- Spring-Hibernate
- Spring+Hibernate
- spring+hibernate
- Spring Hibernate
- spring hibernate
- spring+hibernate
- XML入门精解之CSS和XSL
- C语言中typedef用法详解
- 从天涯回到CSDN
- Mysql笔记
- 很久没看到如此贴切且有教育意义的文章了,看后,还忍不住的笑!
- Spring+hibernate
- 求救!socket 用Select函数检测出来的结果为什么会不正确?
- Oracle数据导出到文本文件的方法
- 撕心裂肺的爱情(我就不信你不哭)
- 深入浅出理解索引结构
- 聘请网络设计师
- XSLT轻松入门第一章:XSLT的概念
- 聘请网络设计师
- XSLT轻松入门第二章:XSLT的实例