hibernate.PersistentObjectException: detached entity passed to persist异常

J2EE 码拜 9年前 (2015-04-05) 1379次浏览 0个评论
 

先上代码

Action

@Scope("prototype")
public class DwxxAction extends BaseAction {
private Dwxx dwxx;(get/set)
}

public String addNewDwxx() {
		UUID uuid = UUID.randomUUID();
		dwxx.setId(uuid.toString());
		System.out.println(dwxx.getId().toString());
		dwxxService.addDwxx(dwxx);
		return showAllDwxx();
	}

实体

@Entity
@Table(name="DWXX")
public class Dwxx {
	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "uuid")
	@Column(name = "ID", unique = true, nullable = false )
	private String id;//信息表编号
	@Column(name="DWBH")
//get set....
}

Dao

public void addDwxx(Dwxx dwxx) {
		getEm().persist(dwxx);
	}

我在网上也找了很多 都说在Action那边加一个@Scope(“prototype”)这个就行 可我加了还是不行
求大神帮忙啊

PS:
@GeneratedValue(generator = “system-uuid”)
@GenericGenerator(name = “system-uuid”, strategy = “uuid”)
着两行注解我也是依葫芦画瓢,具体意思有人能解释下吗,每个属性指什么,通俗易懂点

hibernate.PersistentObjectException: detached entity passed to persist异常
补充下,这是JSP插入新数据的时候发生的问题,报错代码如题
hibernate.PersistentObjectException: detached entity passed to persist异常
20分
@GeneratedValue(generator = "system-uuid")//给数据库主键值
@GenericGenerator(name = "system-uuid", strategy = "org.hibernate.id.UUIDGenerator")
//把strategy写完全,这块是采用的具体的UUID类型
hibernate.PersistentObjectException: detached entity passed to persist异常
引用 2 楼 qu1210 的回复:
@GeneratedValue(generator = "system-uuid")//给数据库主键值
@GenericGenerator(name = "system-uuid", strategy = "org.hibernate.id.UUIDGenerator")
//把strategy写完全,这块是采用的具体的UUID类型

我把strategy改成你说的 启动tomcat时就报一堆错 后来把
@GeneratedValue(generator = “system-uuid”)
@GenericGenerator(name = “system-uuid”, strategy = “uuid”)
着两行去掉了就行了

没人来分给你了


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明hibernate.PersistentObjectException: detached entity passed to persist异常
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!