---
title: "spring3+hibernate3.3.5出现的问题"
author: "edeis"
date: "2011-07-06T13:52:16Z"
tags: []
categories: ["编程语言"]
slug: "spring3-hibernate3-3-5"
draft: false
lastmod: "2011-07-06T14:01:01Z"
id: 1116954
url: "https://edeis.iteye.com/blog/1116954"
---

项目中使用spring3.0.3+hibernate3.3.5final，出现以下异常：


```java

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationcontext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z

```

一对多使用注解如下：

```java

@Entity(name = "room")
public class Room {
	@Id @Column(length=50)
	@GeneratedValue(generator="system-uuid")
	@GenericGenerator(name="system-uuid",strategy="uuid")
	private String room_id;
	@Column(length = 20)
	private String room_type;	
	@Column(length = 30)
	private String room_ip;
	private Integer room_port;
	@Column(length = 100)
	private String room_name;
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "room")
	private List<RoomPartInfo> partInfos;
。。。
}

```


```java

@Entity(name = "RoomPartInfo")
public class RoomPartInfo {
	@Id
	@Column(length = 50)
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "uuid")
	private String part_id;

	@Column(length = 30)
	private String part_type;

	@Column(length = 100)
	private String part_name;

	@ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST,
			CascadeType.PERSIST })
	@JoinColumn(name = "room_id", updatable = false)
	private Room room;

	private Byte part_addr;
。。。
}


```

解决办法：降低hibernate版本到3.3.2，问题解决！