`
kevinhrw
  • 浏览: 187263 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

many to one FK更新問題求解(identifier of an instance)

阅读更多
錯誤如下:
Data Access Failure

identifier of an instance of com.tar.model.CargoType was altered from 402881821bdb7471011bdb75c08e0002 to 402881821bdb7471011bdb7586530001; nested exception is org.hibernate.HibernateException: identifier of an instance of com.tar.model.CargoType was altered from 402881821bdb7471011bdb75c08e0002 to 402881821bdb7471011bdb7586530001

我在論壇上看看別以前發的帖子,沒有找到答案,求解呀!
子類:
public class Cargo extends BaseObject implements java.io.Serializable {
	private CargoType cargoType = new CargoType();
	@ManyToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE})
	@JoinColumn(name = "cargo_type_id")
	public CargoType getCargoType() {
		return this.cargoType;
	}

	public void setCargoType(CargoType cargoType) {
		this.cargoType = cargoType;
	}
}

父類:
public class CargoType extends BaseObject implements java.io.Serializable {
	private String cargoTypeId;
	private String cargoTypeName;
	private Set<Cargo> cargos = new HashSet<Cargo>(0);

	@Column(name = "cargo_type_name", nullable = false)
	public String getCargoTypeName() {
		return this.cargoTypeName;
	}

	public void setCargoTypeName(String cargoTypeName) {
		this.cargoTypeName = cargoTypeName;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "cargoType")
	public Set<Cargo> getCargos() {
		return this.cargos;
	}

	public void setCargos(Set<Cargo> cargos) {
		this.cargos = cargos;
	}
}

form jsp的內容如下:
<form:select path="cargoType.cargoTypeId" cssClass="select medium" cssErrorClass="select medium error" id="cargoType.cargoTypeId" >
<form:option value="" label="Please Select"/>
<form:options items="${cargoTypeList}" itemValue="cargoTypeId" itemLabel="cargoTypeName"/>
</form:select>

有沒有下面這兩行都是報那個錯誤.
String cargoTypeId = request.getParameter("cargoType.cargoTypeId");
cargo.setCargoType(cargoTypeManager.get(cargoTypeId));
			
cargoManager.save(cargo);//調用的是這個方法getHibernateTemplate().merge(object)

cascade變成:
@ManyToOne(cascade = {CascadeType.PERSIST}),不讓它級聯更新,也可以,但這只是一個暫的辦法
分享到:
评论
1 楼 kevinhrw 2009-02-10  
與以前一個帖子是相同的問題:
http://www.iteye.com/topic/112409
但沒有找到答案,請各位幫忙看看.謝謝了~小弟新學hibernate,望指教.

相关推荐

    Hibernate Reference Documentation3.1

    7.5.1. one to many / many to one 7.5.2. one to one 7.5.3. many to many 7.6. More complex association mappings 8. Component Mapping 8.1. Dependent objects 8.2. Collections of dependent objects 8.3. ...

    The Digital Object Identifier initiative: metadata implications

    The Digital Object Identifier initiative: metadata implications Context/status information The purpose of this document is to generate a DOI Foundation consensus paper on metadata, as a companion ...

    VclZip pro v3.10.1

    While it has been tested and has even been used in at least two production applications for several months now prior to initial release, there are so many combinations of property settings, ...

    NewSID(光学习一下代码就可以了,没看清楚介绍别运行)

    Introduction Many organizations use disk image cloning to perform mass rollouts of Windows. This technique involves copying the disks of a fully installed and configured Windows computer onto the disk...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    connector's end point moving, the link is breaks if the move was not on one of the flex-controls connection points. Contain False as default. - ADD Added ControlDocRect parameter in event ...

    微软内部资料-SQL性能优化5

    Each index row in node pages contains an index key (or set of keys for a composite index) and a pointer to a page at the next level for which the first key value is the same as the key value in the ...

    park an autonomous vehicle

    1. A practical approach to motion generation and control for an omnidirectional mobile robot Paromtchik, I.E.; Rembold, U. Robotics and Automation, 1994. Proceedings., 1994 IEEE International ...

    计算机网络第六版答案

    Many of these data centers are located in, or close to, lower tier ISPs. Therefore, when Google delivers content to a user, it often can bypass higher tier ISPs. What motivates content providers to ...

    Hibernate3的帮助文档

    7.2.4. 值集合于多对多关联(Collections of values and many-to-many associations) 7.2.5. 一对多关联(One-to-many Associations) 7.3. 高级集合映射(Advanced collection mappings) 7.3.1. 有序集合(Sorted...

    Java_implementation_of_access_control_identifier_c_The Class

    Java实现标识符对类的访问控制代码Java implementation of access control identifier code of the class

    解决error C2065: '_beginthreadex' :undeclared identifier

    报错误error C2065: '_beginthreadex' :undeclared identifier

    Fsharp Succinctly(Syncfusion,2012)

    In the simplest terms, once a value is assigned to an identifier it never changes, functions do not alter parameter values, and the results that functions return are completely new values. In typical...

    CPU-Identifier, 检查你的A9芯片制造商.zip

    CPU-Identifier, 检查你的A9芯片制造商 CPU标识符这个小应用程序可以检测你的iPhone的CPU芯片组。 对于 iPhone/6s,它还可以检测到A9芯片的制造商。编译的( 签名) 二进制文件将把芯片模型。设备模型和一个惟一 id ( ...

    hibernate 框架详解

    一对多(one to many) /多对一( many to one) 8.5.2. 一对一(one to one) 8.5.3. 多对多(many to many) 9. 组件(Component)映射 9.1. 依赖对象(Dependent objects) 9.2. 在集合中出现的依赖对象 ...

    最全Hibernate 参考文档

    7.4.1. 一对多(one to many) / 多对一(many to one) 7.4.2. 一对一(one to one) 7.5. 使用连接表的双向关联(Bidirectional associations with join tables) 7.5.1. 一对多(one to many) /多对一( many to ...

    PEiD(PE Identifier)查壳工具

    PEiD(PE Identifier)是一款著名的查壳工具,其功能强大,几乎可以侦测出所有的壳,其数量已超过470 种PE 文档 的加壳类型和签名。

    Hibernate中文详细学习文档

    7.4.1. 一对多(one to many) / 多对一(many to one) 7.4.2. 一对一(one to one) 7.5. 使用连接表的双向关联(Bidirectional associations with join tables) 7.5.1. 一对多(one to many) /多对一( many ...

    Hibernate3+中文参考文档

    7.5.1. 一对多(one to many) /多对一( many to one) 7.5.2. 一对一(one to one) 7.5.3. 多对多(many to many) 8. 组件(Component)映射 8.1. 依赖对象(Dependent objects) 8.2. 在集合中出现的依赖对象 ...

    A Novel RFID Authentication Protocol with Ownership Transfer.doc

    Impersonation: An attacker forges a tag or a reader as an authenticated one to steal the information in the database server. Eavesdropping: It is easy for eavesdroppers to get the signal from the ...

    File Format Identifier 1.5.3

    一款辅助进行病毒分析的工具,它包括各种文件格式识别功能,使用超级巡警的格式识别引擎,集查壳、虚拟机脱壳、PE文件编辑、PE文件重建、导入表抓取(内置虚拟机解密某些加密导入表)、进程内存查看/DUMP、附加数据...

Global site tag (gtag.js) - Google Analytics